shinyWidgets icon indicating copy to clipboard operation
shinyWidgets copied to clipboard

Select a whole group in pickerInput

Open emaigne opened this issue 7 years ago • 1 comments

First of all, thank you for your wonderful package ! I am currently using the pickerInput, with grouped choices (in a list). I am looking for a way to select/unselect a whole groupe in one click (ex. by clicking on the name of the group or something else...)

In the following example I would like to quickly select all the "listA" choices.

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

ui <- fluidPage(
  br(),
  pickerInput(
    inputId = "p1",
    label = "Default",
    multiple = TRUE,
    choices = list("listA"=rownames(mtcars)[1:16], "listB"=rownames(mtcars)[17:32]),
    selected = rownames(mtcars)
  )
)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)

Thank you Elise

emaigne avatar Nov 16 '17 10:11 emaigne

Hi, You're welcome :) That's an interesting fonctionnality ! However I don't know if it's possible... I'll look into it and let you know.

Victor

pvictor avatar Nov 16 '17 16:11 pvictor

Did this ever get looked in to further? I've found that it's a piece of functionality that is quite often asked about.

JGWestie avatar Aug 30 '22 13:08 JGWestie

This functionnality is available in virtualSelectInput() (added in shinyWidgets v0.7.0):

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  fluidRow(
    column(
      width = 4,
      virtualSelectInput(
        inputId = "my_id",
        label = "Select groups :",
        choices = list(`East Coast` = list("NY", "NJ", "CT"),
                       `West Coast` = list("WA", "OR", "CA"),
                       `Midwest` = list("MN", "WI", "IA")),
        multiple = TRUE
      )
    ),
    column(
      width = 4,
      verbatimTextOutput("res")
    )
  )
  
  
)

server <- function(input, output, session) {
  
  output$res <- renderPrint(input$my_id)
  
}

shinyApp(ui, server)

But I don't think pickerInput will ever support it.

Victor

pvictor avatar Aug 30 '22 14:08 pvictor

Thanks for the quick answer! That's a shame, but it makes sense not to focus on that feature in pickerInput if it exists and works well in virtualSelectInput.

JGWestie avatar Aug 30 '22 14:08 JGWestie

I din't know virtualSelectInput but it does exactly what I wanted. Thanks !

emaigne avatar Sep 05 '22 08:09 emaigne