Hi,
I would like to have a drop down input where the options are grouped by the values of another column. I have found pickerInput can do this by using a lists of options in the choices argument.
However the problem is different groups can have the same choices, if a user selects a choice under one group they would assume that they were selecting that choice within that group, but as the pickerInput only returns the choice and not the group the choice is contained within, I can't find a way to capture than information. Ultimately I would like it to return a concatenated group~choice value which I could use to filter my data (by making a corresponding concatenated field)
Can the 'group' information be returned by pickerInput, are there alternative input types that can do this?
Here is an example of what I have so far
if (interactive()) {
library(shiny)
library(shinyWidgets)
Group = c(
"Group1",
"Group1",
"Group1",
"Group1",
"Group2",
"Group2",
"Group2",
"Group2",
"Group3"
)
Choice = c(
"Choice1",
"Choice2",
"Choice3",
"Choice4",
"Choice1",
"Choice2",
"Choice3",
"Choice4",
"Choice5"
)
df <- data.frame(Group, Choice)
df <- lapply(split(df$Choice, df$Group), as.list)
ui <- fluidPage(
pickerInput(
inputId = "groups",
choices = df,
multiple = TRUE
),
verbatimTextOutput(outputId = "res_grp")
)
server <- function(input, output) {
output$res_grp <- renderPrint(input$groups)
}
shinyApp(ui, server)
}
Any help would be much appreciated
many thanks