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.
selectList <- 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)
According to this thread - https://groups.google.com/forum/#!topic/shiny-discuss/doHpFM6ZOGg, the issue had a fix in some old private branch. Latest install I am using is this and I see the slowness problem.
packageVersion('shiny')
[1] ‘0.13.2’
Any options I have to make this behave differently?
Additional need:
I would also like the selectized inputs to be dependent on a radio button input as follows. But, for some reason, I can't make the server side selectize input to work with observeEvent on the radio button. Any thoughts on what I am doing wrong?
# mylist
selectList1 <- sapply(1:15000, function(x) paste0(x, "_", paste(sample(LETTERS, 10), collapse = '')))
selectList2 <- 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
),
radioButtons('letterType',
'Select a Letter Type:',
choices = c('Upper Case' = 'upper',
'Lower Case' = 'lower'),
selected = 'upper',
inline = TRUE)
)
# server
server <- function(input, output, session) {
selectListReactive <- reactive({
validate(need(is.null(input$letterType), FALSE))
if (input$letterType == 'upper')
selectList1
else
selectList2
})
observeEvent(input$letterType, {
updateSelectizeInput(session = session, inputId = 'mylist',
choices = c(Choose = '', selectListReactive()),
server = TRUE)
})
}
# app
shinyApp(ui = ui, server = server)
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 = '')))
names(selectList) = ""
ui <- fluidPage(
selectInput('mylist', 'Select Something',
choices = c(Choose = '', selectList),
selected = 1)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With