0

Is there a way to activate multiple selection in updatePickerInput()?

library("shiny")
library("shinyWidgets")

ui <- fluidPage(
  tags$h2("Update pickerInput"),
  
  fluidRow(
    column(
      width = 5, offset = 1,
      pickerInput(
        inputId = "p1",
        label = "classic update",
        choices = rownames(mtcars)
      )
    )
    
  ),
  
  fluidRow(
    column(
      width = 10, offset = 1,
      sliderInput(
        inputId = "up",
        label = "Select between models with mpg greater than :",
        width = "50%",
        min = min(mtcars$mpg),
        max = max(mtcars$mpg),
        value = min(mtcars$mpg),
        step = 0.1
      )
    )
  )
  
)

server <- function(input, output, session) {
  
  observeEvent(input$up, {
    mtcars2 <- mtcars[mtcars$mpg >= input$up, ]
    
    # Method 1
    updatePickerInput(session = session, inputId = "p1",
                      choices = rownames(mtcars2))
    
    # Method 2
    disabled_choices <- !rownames(mtcars) %in% rownames(mtcars2)
    
  }, ignoreInit = TRUE)
  
}

shinyApp(ui = ui, server = server)
firmo23
  • 7,490
  • 2
  • 38
  • 114
  • Not very sure what you are trying to do here. If you want to select more than one choice in update, add `multiple = T` in `pickerInput` and change `choices` to `selected = rownames(mtcars2)` in `updatePickerInput` – lz100 Jun 06 '22 at 19:33
  • so updatePickerInput does not have multiple argument – firmo23 Jun 06 '22 at 19:47
  • yeah, it inherits from `pickerInput`. – lz100 Jun 06 '22 at 19:48

0 Answers0