Shiny selectInput very slow on larger data (~15,000 entries) in browser
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
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)