0

I have read all possible posts and threads about server-side selectizeInput, here and elsewhere... but no matter what I try, I cannot make it work.

I tried a few months back and eventually just gave up, but now I really need to make it work, so really hoping someone can shed some light.

I have my Shiny app that I built with "Package for Shiny app using Golem" in RStudio, and I pass my data around using reactive values.

The problem I face is very simple, I have a long list of IDs I want to show in a selectizeInputdrop-down menu, but I get the following warning:

Warning: The select input "bulk_side_ui_1-selected_ids" contains a large number of options; consider using server-side selectize for massively improved performance. See the Details section of the ?selectizeInput help topic.

This is my working code on the client side:

UI:

test_side_ui <- function(id, r){
  ns <- NS(id)
  tagList(
    uiOutput(outputId = ns("selected_ids"))
  )
}

SERVER:

  test_side_server <- function(id, r){
  moduleServer( id, function(input, output, session){
    ns <- session$ns

    output$selected_ids <- renderUI({
      selectizeInput(inputId = ns("selected_ids"), label = "My IDs:",
                     choices = paste0('id',1:60000),
                     selected = NULL,
                     multiple = TRUE,
                     options = list(maxOptions = 100000L))
    })

    # add selection to reactive values
    observeEvent(input$selected_ids, {
      r$selected_ids <- input$selected_ids
    }, ignoreNULL = FALSE)
  })
}

This works, but shows the warning, and it is indeed a bit slow.

My best attempt at server-side selectizeInput, after going through many posts, is the following, which still does not fully work...

UI:

test_side_ui <- function(id, r){
  ns <- NS(id)
  tagList(
    selectizeInput(inputId = ns("selected_ids"), label = "My IDs:", choices = NULL, multiple = TRUE, options = list(maxOptions = 10000L))
  )
}

SERVER:

  test_side_server <- function(id, r){
  moduleServer( id, function(input, output, session){
    ns <- session$ns

    observeEvent(input$selected_ids, {
      r$selected_ids <- input$selected_ids
      updateSelectizeInput(session, inputId = "selected_ids", choices = paste0('id',1:60000), selected = r$selected_ids, server = TRUE)
    }, ignoreNULL = FALSE)
  })
}

This seems to enter an infinite loop where selectizeInput is constantly updated from NULL to the selected values...

Anybody can help please? I don't know what I'm doing wrong and I'm really at a loss here... Thanks!

DaniCee
  • 2,397
  • 6
  • 36
  • 59
  • I haven't tried running the code, but I think the problem is with `selected = r$selected_ids` that should be a constant value like your first choice `selected = "id1"` – Vida Dec 12 '22 at 15:45
  • but it needs to be updated with each selection... – DaniCee Dec 12 '22 at 15:47

0 Answers0