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

后端 未结 2 1614
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

    0 讨论(0)
  • 2020-12-23 18:44

    I did it faster with data.table package:

    library(data.table)
    selectList <- as.data.table(sapply(1:15000, function(x) paste(sample(letters, 10), collapse = '')))
    ui <- fluidPage(
      selectInput('mylist', 'Select Something',
                  choices = c(Choose = '', selectList),
                  selected = 1)
    )
    
    server <- function(input, output) {
    }
    
    shinyApp(ui = ui, server = server)
    
    0 讨论(0)
提交回复
热议问题