Shiny selectInput very slow on larger data (~15,000 entries) in browser

后端 未结 2 1615
Happy的楠姐
Happy的楠姐 2020-12-23 18:03

I have this basic shiny app, and it is blazing fast in the \'Viewer\', but when I use the \'Open in Browser\' option, the select input choices take a while to load.

2条回答
  •  滥情空心
    2020-12-23 18:42

    Hi try to put the choices in the server with updateSelectizeInput and use server = TRUE to store the choices server-side, e.g. :

    library("shiny")
    # mylist
    selectList <- sapply(1:15000, function(x) paste0(x, "_", paste(sample(letters, 10), collapse = '')))
    # ui
    ui <- fluidPage(
      selectizeInput(
        inputId = 'mylist', label = 'Select Something',
        choices = NULL,
        selected = 1
      )
    )
    # server
    server <- function(input, output, session) {
      updateSelectizeInput(session = session, inputId = 'mylist', choices = c(Choose = '', selectList), server = TRUE)
    }
    # app
    shinyApp(ui = ui, server = server)
    

    You have to use selectizeInput and not selectInput for this to work

提交回复
热议问题