stla/shinySelect

`updateSelectControlInput` doesn't work correctly

Closed this issue · 2 comments

updateSelectControlInput doesn't work as expected, specifically when:

  1. choices = NULL (i.e. keep the same choices)
  2. removing and/or adding choices (& trying to select new choices)

Minimal Reprex:

library(shiny)
library(shinySelect)

ui <- fluidPage(
  fluidRow(
    column(
      12,
      shiny::actionButton(
        "update",
        "Update Select Control Input"
      ),
      shinySelect::selectControlInput(
        "test",
        "Test",
        choices = list("A", "B", "C"),
        selected = c("A", "B"),
        multiple = TRUE,
        sortable = TRUE,
        animated = TRUE,
        closeMenuOnSelect = FALSE
      )
    )
  )
)

server <- function(input, output, session) {
  shiny::observeEvent(input$test, {
    print(input$test)
  })

  shiny::observeEvent(input$update, {
    shinySelect::updateSelectControlInput(
      session,
      "test",
      choices = list(
        "A",
        "B",
        "D"
      ),
      selected = list(
        "A",
        "D"
      )
    )
  })
}

shinyApp(ui, server)
stla commented

Thanks!

Indeed, the code was totally wrong. I've just pushed a new version for which your example works. I have not tested other examples yet.

@stla I really appreciate the quick response & fix! It seems to be working correctly now, but I'll be sure to reopen the issue if I run into any related bugs. Thanks!