Skip to content

updateSelectizeInput(options = list(...)) can change the selected value #4278

@cpsievert

Description

@cpsievert

A minimal reprex is below. Note how, after the update happens, Option 3 is selected, instead of Option 1.

Seems this isn't an issue when multiple = TRUE

library(shiny)

ui <- bslib::page_fluid(
  selectizeInput("foo", "Foo", choices = c("Option 1", "Option 2", "Option 3"))
)

server <- function(input, output, session) {
  observe({
    updateSelectizeInput(
      inputId = "foo",
      options = list(placeholder = "Select an option")
    )
  })
}

shinyApp(ui, server)
Image

A workaround is to include the currently selected value on update:

updateSelectizeInput(
    inputId = "foo",
    selected = isolate(input$foo),
    options = list(placeholder = "Select an option")
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions