warning: use server-side selectize for massively improved performance in RShiny
Asked Answered
W

2

7

In an RShiny app, I am receiving the warning message Warning message: The select input "the_input_id" contains a large number of options; consider using server-side selectize for massively improved performance. See the Details section of the ?selectizeInput help topic.

I have a named vector namelist of length == 3000 that is used for the dropdown choices. I've tried the following two things to get rid of this warning:

ui

selectizeInput(
  inputId = 'the_input_id', label = 'Player 1 Search:', choices = namelist, selected = NULL,
  options = list(placeholder = 'Please select an option below', onInitialize = I('function() { this.setValue(""); }'))
)

uiOutput(outputId = 'this_id')

server

updateSelectizeInput(session = session, inputId = 'the_input_id', label = 'Player 1 Search:', choices = namelist, server = TRUE,
                    options = list(placeholder = 'Please select an option below', onInitialize = I('function() { this.setValue(""); }')),
                           selected = ""
                           )

output$this_id<-renderUI ({
    selectizeInput(inputId = 'this_id', "Player 2 Search:", namelist,
                   options = list(
                     placeholder = 'Please select an option below',
                     onInitialize = I('function() { this.setValue(""); }')
                   ))
})

The approach for the_input_id is to use a selectizeInput() in the UI, and an updateSelectizeInput() in the server (I thought this was the correct approach for server-side selectize). The approach for this_id is to use an uiOutput() in the UI, and a renderUI + selectizeInput on the server. Both of these approaches give the same warning message that I posted above. How can I resolve the issue / to get rid of this warning message.

Whelk answered 25/2, 2021 at 22:19 Comment(0)
L
6

I think the issue is that you are still generating the list of options in the UI, using choices = namelist.

Try using choices = NULL instead.

To get it working, follow the example in the section "Server-side selectize" of this guide.

Ladyship answered 25/2, 2021 at 22:33 Comment(1)
when i use choices = NULL in the UI, then i am never able to see the options. so it seems like the updateSelectizeInput is never getting called from the server?Whelk
A
0

Even when you do render it in server it will not solve your problem because this error may mean that the namelist contain a large number of duplicates, for better performance it's better to render selectize input in the server reason of its size.

namelist should not contain duplicates, and I guess the following will fix it:

choices = unique(namelist) or choices = unique(factor(namelist))

Server:

updateSelectizeInput(
  session,
  inputId = 'id',
  label   = '',
  choices = unique(namelist)
)

UI:

shiny::selectizeInput(
  inputId   = "id",
  label     = NULL,
  choices   = '',
  options   = list(...)
)
Anaheim answered 28/8, 2021 at 22:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.