Shiny code not working - Invalid 'type' (list)

My shiny app is running, but I do not get the output I desire. I get the following error:

Listening on http://127.0.0.1:4093
Warning: Error in max: invalid 'type' (list) of argument
  96: collapsibleTreeSummary
  95: func [O:\DIVISIONAL DRIVES\research/2019 \app\apps/server.R#28]
  82: origRenderFunc
  81: output$plot
   1: runApp

Below is my code:

raw <- read_rds("RSdata.rds")

shinyServer(function(session, input, output) {
  
  p <- NULL
  data.1 <- reactive(
    if(input$level == "All types" & input$gno == "In chart" & input$year == "2018"){
      data.1 <- filter(raw,`Attempt Quantity` != 0 ,`Included in GNO performance tables` == 1, `Year` == 2018) %>%
        group_by(`Field of work`,`Sub-Field of work`, `Company`) %>% summarize(`Attempt Quantity` = sum(`Attempt Quantity`))}
    else if(input$level == "All types" & input$gno == "In chart" & input$year == "2017"){
      data.1 <- filter(raw,`Attempt Quantity` != 0 ,`Included in GNO performance tables` == 1, 'Year' == 2017) %>%
        group_by(`Field of work`,`Sub-Field of work`, `Company`) %>% summarize(`Attempt Quantity` = sum(`Attempt Quantity`))} 
    else if(input$level != "All types" & input$gno == "In chart"& input$year=="2018"){
      data.1 <- filter(raw, Level %in% input$level ,`Attempt Quantity` != 0,`Included in GNO performance tables` == 1, 'Year' == 2018) %>% group_by(`Field of work`,`Sub-Field of work`, `Company`) %>% summarize(`Attempt Quantity` = sum(`Attempt Quantity`))}
    else if(input$level != "All types" & input$gno == "In chart"& input$year=="2017"){
      data.1 <- filter(raw, Level %in% input$level ,`Attempt Quantity` != 0,`Included in GNO performance tables` == 1, 'Year' == 2017) %>% group_by(`Field of work`,`Sub-Field of work`, `Company`) %>% summarize(`Attempt Quantity` = sum(`Attempt Quantity`))} 
    else if(input$level == "All types" & input$gno != "In chart"&input$year=="2018" ){
      data.1 <- filter(raw, `Attempt Quantity` != 0, 'Year' == 2018)%>% group_by(`Field of work`,`Sub-Field of work`,`Company`) %>%summarize(`Attempt Quantity` = sum(`Attempt Quantity`)) } 
    else if(input$level == "All types" & input$gno != "In chart"&input$year=="2017" ){
      data.1 <- filter(raw, `Attempt Quantity` != 0, 'Year' == 2017)%>% group_by(`Field of work`,`Sub-Field of work`,`Company`) %>%summarize(`Attempt Quantity` = sum(`Attempt Quantity`)) }
    else if(input$level != "All types" & input$gno != "In chart"&input$year=="2018" ){
      data.1 <- filter(raw, Level %in% input$level,`Attempt Quantity` != 0, `Year`==2018)%>% group_by(`Field of work`,`Sub-Field of work`,`Company`) %>%summarize(`Attempt Quantity` = sum(`Attempt Quantity`)) }
    else{data.1 <- filter(raw, Level %in% input$level,`Attempt Quantity` != 0, `Year`==2017) %>% group_by(`Field of work`,`Sub-Field of work`, `Company`) %>% summarize(`Attempt Quantity` = sum(`Attempt Quantity`))})
  
  
  output$plot <- renderCollapsibleTree({ 
    dat <- data.1()
    p <- collapsibleTreeSummary(
      dat, hierarchy = c("Field of work","Sub-Field of work","Company"), root = "Qualification framework", attribute = "Attempt Quantity", inputId = "node", zoomable = FALSE,
      fillFun = colorspace::heat_hcl, fontSize = 10)
    p
  })
  
  # Table
  df <- reactive({
    
    if(input$gno == "In chart"){z <- filter(raw, `Included in GNO performance tables` == 1)}
    else{z <- raw}
    
    if(input$year == "2018"){z <- filter(raw, `Year` == 2018)}
    else{z <- filter(raw, `Year` == 2017)}
    
  
    if(input$level != "All types"){z <- filter(z, Level %in% input$level)}
    else{z <- z}
    
  
    


    if(is.null(input$node$`Field of work`)){
      v <-  group_by(z, `Field of work`) %>% summarise(Qualifications = n(), `Companys` = length(unique(`Company`)), Certificates = sum(`Attempt Quantity`))
    } else if(!is.null(input$node$`Field of work`) & is.null(input$node$`Sub-Field of work`)){
      r <- input$node$`Field of work`
      v <- filter(z, `Field of work` %in% r) %>% group_by(`Sub-Field of work`) %>% summarise(Qualifications = n(), `Companys` = length(unique(`Company`)), Certificates = sum(`Attempt Quantity`))
    } else if(!is.null(input$node$`Field of work`) & !is.null(input$node$`Sub-Field of work`) & is.null(input$node$`Company`)){
      r <- input$node$`Field of work`
      s <- input$node$`Sub-Field of work`
      v <- filter(z, `Field of work` %in% r & `Sub-Field of work` %in% s) %>% group_by(`Company`) %>% summarise(Qualifications = n(), Certificates = sum(`Attempt Quantity`))
      
    } else{
      r <- input$node$`Field of work`
      s <- input$node$`Sub-Field of work`
      u <- input$node$`Company`
      v <- filter(z, `Field of work` %in% r & `Sub-Field of work` %in% s & `Company` %in% u) %>% group_by(`Qualification Title`) %>% summarise(Certificates = sum(`Attempt Quantity`))
    }
  })
  
  # Table plotting
  output$table <- renderDataTable({
    datatable(df(), options = list(initComplete = JS(
      "function(settings, json) {",
      "$(this.api().table().header()).css({'background-color': '#000', 'color': '#fff'});",
      "}"), pageLength = 20, dom = 'tip', order = list(list(ncol(df())-1, 'desc'))), rownames = F, class = 'compact row-border stripe hover') %>%
      formatCurrency('Certificates',currency = "", interval = 3, mark = ",", digits = 0)
    })
  
  output$downloadData <- downloadHandler(
    filename = function(){
      if(!is.null(input$node$`Field of work`) & !is.null(input$node$`Sub-Field of work`) & !is.null(input$node$`Company`)){
        paste("Qual_pathway","_",input$node$`Field of work`,"_",input$node$`Sub-Field of work`,"_",input$node$`Company`,".csv", sep = "")
      } else if(!is.null(input$node$`Field of work`) & !is.null(input$node$`Sub-Field of work`) & is.null(input$node$`Company`)){
        paste("Qual_pathway","_",input$node$`Field of work`,"_",input$node$`Sub-Field of work`,".csv", sep = "")
      } else if(!is.null(input$node$`Field of work`) & is.null(input$node$`Sub-Field of work`) & is.null(input$node$`Company`)){
        paste("Qual_pathway","_",input$node$`Field of work`,".csv", sep = "")
      } else{
        paste("Qual_pathway.csv", sep = "")
      }
    },
    content = function(filename) {
      write.csv(df(), filename, row.names = FALSE)
    }
  )
  
  observeEvent(input$reset_input,{
    p <- NULL
    output$plot <- renderCollapsibleTree({
      dat <- data.1()
      p <- collapsibleTreeSummary(
        dat, hierarchy = c("Field of work","Sub-Field of work","Company"), root = "Qualification framework", attribute = "Attempt Quantity", inputId = "node", zoomable = FALSE,
        fillFun = colorspace::heat_hcl, fontSize = 11)
      p
    })

    session$sendCustomMessage(type = "resetValue", message = "node")
    })
  
  observeEvent(input$gno,{
    session$sendCustomMessage(type = "resetValue", message = "node")
  })
  
  observeEvent(input$level,{
    session$sendCustomMessage(type = "resetValue", message = "node")
  })
  
  
  observeEvent(input$year,{
    session$sendCustomMessage(type = "resetValue", message = "node")
  })
  
  ## reactive text ##
  formulaText <- reactive({
    if(nrow(df()) == 0){paste("There are no qualifications matching your search")}
    else if(!is.null(input$node$`Field of work`) & !is.null(input$node$`Sub-Field of work`) & !is.null(input$node$`Company`)){
      paste(input$node$`Field of work`,">",input$node$`Sub-Field of work`,">",input$node$`Company`, sep = " ")
    } else if(!is.null(input$node$`Field of work`) & !is.null(input$node$`Sub-Field of work`) & is.null(input$node$`Company`)){
      paste(input$node$`Field of work`,">",input$node$`Sub-Field of work`, sep = " ")
    } else if(!is.null(input$node$`Field of work`) & is.null(input$node$`Sub-Field of work`) & is.null(input$node$`Company`)){
      paste(input$node$`Field of work`)
    } else{
      paste("Choose a Field of work", sep = "")
    }
  })
  
  
  # Return the formula text for printing as a caption
  output$caption <- renderText({
    formulaText()
  })
  
  
})

Hi,

To debug this, try to isolate the data that goes into the function when it crashes, and then debug it outside of the Shiny app.

To do this, force a local save of the variable 'dat' in the renderCollapsibleTree function by adding this line: myVariable <<- data.1(), the <<- forces a variable to be saved locally and being accessible after the app craches.

output$plot <- renderCollapsibleTree({ 
    dat <- data.1()
    myVariable <<- data.1()
    p <- collapsibleTreeSummary(
      dat, hierarchy = c("Field of work","Sub-Field of work","Company"), root = "Qualification framework", attribute = "Attempt Quantity", inputId = "node", zoomable = FALSE,
      fillFun = colorspace::heat_hcl, fontSize = 10)
    p
  })

Now run the app until it crashes. Then close the app, and the variable myVariable should be available.

Now look at this data and even plug it in to the function collapsibleTreeSummary and see where it goes wrong. Hopefully this will make it easier for you to track the error...