Slow updateSelectizeInput for large sets of selected entries

Dear colleagues,

By design I need to have selectizeInput with thousands of simultaneously selected items, and automatically update the set of selected items as a reaction to certain events. I observe that in case of a large set of pre-selected items in ui, the element itself is created promptly: for the code

  shinyApp(
    ui <- fluidPage(
      selectizeInput("x", "Choose:",
                              choices = as.character(1:10000),
                              selected = as.character(2:2000),
                              multiple = TRUE
       )
     ),
     server <- function(input, output, session) {
     }
  )

loading takes just few seconds.

Yet, if I create a similar element using updateSelectizeInput, it take much longer:

  shinyApp(
    ui <- fluidPage(
      selectizeInput("x", "Choose:",
                             choices = NULL,
                             selected = NULL,
                             multiple = TRUE
       )
    ),
    server <- function(input, output, session) {
        shiny::updateSelectizeInput(session, "x", choices = as.character(1:10000), selected = as.character(2:2000))
    }
  )

Could you please explain me the reason of such a huge difference in speed? Am I right that at the level of java script for the updateSelectizeInput element-wise adding of selected elements is performed in a for loop, and it is the reason for speed decrease? And, even more important, could you please suggest how to get adequate speed for updateSelectizeInput with thousands of items in selected? Thank you!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.