selectizeInput paramter 'multiple' unchangeable when updated server-side

Hi,

Im not able to change the multiple argument in a selectizeInput (FALSE per default) back to TRUE from the server part of the app. I use the updateSelectizeInput function with the corresponding option parameter to achive the change.
(I need to set the server parameter to TRUE by the way - if set to FALSE, everything works as expected)

Here is a code example:

library(shiny)

ui <- fluidPage(
  selectizeInput(
    inputId = "name",
    label = "Select Name:",
    choices = NULL
  )
)
server <- function(input, output, session) {
  updateSelectizeInput(
    inputId = "name",
    choices = c("Markus", "Lisa", "Peter"),
    options = list(maxItems = 10),
    server = TRUE # set consciously, I have a big list to handle
  )
}
shinyApp(ui, server)

I found a similar question here. Unfortunately it was closed without an answer.
Setting the multiple parameter in the ui part donĀ“t helps me, because I want to decide about the argument in the server-part.

My go to picker widget is pickerInput from shinywidgets, it may be an option for you to explore.
In the case of shiny selectize I found the following possibility, which is to set it up as allowing multiples, but on the fly limiting the max selection 1 from the update.
If you want it then to be truly multiple relax the max selection to a higher number than 1, even Inf if needed

library(shiny)

ui <- fluidPage(
  selectizeInput(
    inputId = "name",
    label = "Select Name:",
    choices = NULL,
    selected=NULL,
    multiple = TRUE
  )
)
server <- function(input, output, session) {
  updateSelectizeInput(
    inputId = "name",
    choices = c("Markus", "Lisa", "Peter"),
    selected=character(0),
    options = list(maxItems = 1), # from Inf to 1
    server = TRUE
  )
}
shinyApp(ui, server)

Thanks for your suggestion!
In my case this is a solution I can work with.

Still I wonder why the function is not consistent.
If the param server in updateSelectizeInput is FALSE you can change a selectizeInput to support multiple from the server by setting the options parameter. If set to TRUE, it is not possible. See this example:

library(shiny)

ui <- fluidPage(
  selectizeInput(
    inputId = "name",
    label = "Select Name:",
    choices = NULL,
    multiple = FALSE
  )
)
server <- function(input, output, session) {
  updateSelectizeInput(
    inputId = "name",
    choices = c("Markus", "Lisa", "Peter"),
    # changes 'multiple' param in selectizeInput to TRUE
    options = list(maxItems = 10),
    # if server = TRUE, changing 'multiple' param is not possible anymore 
    # server = TRUE
  )
}
shinyApp(ui, server)

In your solution the multiple output stays multiple in a way (no dropdown symbol on the right). Im my case that is fine but I can think of cases where you want a "real" single-select dropdown.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.