4

Does anyone know of a way to use shinyWidgets::pickerInput() with a large number of choices, but speed up the rendering? (similar to server-side selectize using updateSelectizeInput())

What I'm ultimately trying to do: have a shinyWidgets pickerInput() with a large number of choices (~1M).

The problem: it takes a really long time for the app to load with that many choices.

I know that one workaround is to use the shiny::selectizeInput() UI element, because there is a neat way to do a server-side shiny::updateSelectInput(), which makes both the loading of the initial UI element and the subsequent update with a bunch of options run pretty quickly (as described in this article).

However, I really like the formatting options and flexibility that shinyWidgets::pickerInput() offers.

Examples:

This works and loads quickly, but uses shiny::selectizeInput() instead of shinyWidgets::pickerInput(), which I want to use.

library(shiny)

ui = shiny::fluidPage(
  shiny::uiOutput(outputId = "ui_output")
)

server = function(input, output) {
  
  output$ui_output = shiny::renderUI({
    
    shiny::selectizeInput(
      inputId = "select",
      label = "Select:",
      choices = NULL
    )
    
  })
  
  shiny::observe({
    
    shiny::updateSelectizeInput(
      inputId = "select",
      choices = 1:1000000,
      selected = 1,
      server = TRUE
    )
    
  })
  
}

shiny::shinyApp(ui, server)

When trying to do the same with shinyWidgets::pickerInput(), I tried both loading the choices directly into the UI initially:

server = function(input, output) {
  
  output$ui_output = shiny::renderUI({
    
    shinyWidgets::pickerInput(
      inputId = "select",
      label = "Select:",
      choices = 1:1000000
    )
    
  })
  
}

And also trying to same logic that I used in the first example, which is to initially load the UI object with choices = NULL, and then have a shiny::observe() call that updates the UI element's choices (this works, but is really slow):

server = function(input, output) {
  
  output$ui_output = shiny::renderUI({
    
    shinyWidgets::pickerInput(
      inputId = "select",
      label = "Select:",
      choices = NULL
    )
    
  })
  
  shiny::observe({
    
    shinyWidgets::updatePickerInput(
      session = getDefaultReactiveDomain(),
      inputId = "select",
      choices = 1:1000000,
      selected = 1
    )
    
  })
  
}
ForceLeft415
  • 277
  • 4
  • 14
  • 2
    This is still an [open issue](https://github.com/dreamRs/shinyWidgets/issues/184) in shinyWidgets repo. The serverside updatePickerInput is not implemented yet but requested a lot. – bretauv Oct 19 '21 at 08:49
  • @bretauv ah, bummer. Thanks for the head up on that :) – ForceLeft415 Oct 19 '21 at 17:30

0 Answers0