Wang
Wang

Reputation: 1460

Shiny: Warning: The select input contains a large number of options; consider using server-side selectize for massively improved performance

I have a table, which contains 1500 columns. When I tried to use shiny to get the colnames, I got the following warning:

The select input contains a large number of options; consider using server-side selectize for massively improved performance.

So I replaced varSelectInout and updateVarSelectInput to varSelectizeInput and updateVarSelectizeInput. But the warning is still there. I don't know how to get rid of the warning and improve the performance.

Here is my example:

library(shiny)

ui = fluidPage(
  fileInput(inputId = "rawFile", label="File"), 
  varSelectInput(inputId = "getColumn", label="Get Column", data = "")
  plotOutput("box")
)

server = function(input, output, session){
  
  df <- reactive({
    inFile <- input$rawFile
    if (is.null(inFile)){return(NULL)}
    read.csv(inFile$datapath, header = T)
  })
  
 observeEvent(df(),{
    updateVarSelectInput(inputId = "getColumn", data = df())
  })
  
 

}

shinyApp(ui, server)

Upvotes: 1

Views: 784

Answers (1)

Zac Warham
Zac Warham

Reputation: 157

You are missing server = TRUE as suggested by @Waldi and session

Here is the full code using Selectize

library(shiny)

ui = fluidPage(
  fileInput(inputId = "rawFile", label="File"), 
  varSelectizeInput(inputId = "getColumn", label="Get Column", data = ""),
  plotOutput("box")
)

server = function(input, output, session){
  
  df <- reactive({
    inFile <- input$rawFile
    if (is.null(inFile)){return(NULL)}
    read.csv(inFile$datapath, header = T)
  })
  
  observeEvent(df(),{
    updateVarSelectizeInput(session, inputId = "getColumn", data = df(), server = TRUE)
  })
}

shinyApp(ui, server)

Upvotes: 2

Related Questions