I'm trying to provide an list of options to select from across a few selectInput dropdowns. I want each dropdown to only list items that have not already been selected in any of the others. What I have below will reduce the options for a second selectInput based on already selected values. But making selections in second box resets everything, so cannot e.g., select ABC in 1, DEF in 2, and then have choice of GHIJ in 3.
I was trying an observer but not getting there. Any suggestions on how to implement would be appreciated.
library(shiny)
dataOptions <- c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J')
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
wellPanel(
uiOutput("dynamicui_g1"),
uiOutput("dynamicui_g2"),
uiOutput("dynamicui_g3")
)),
mainPanel()
)
)
server <- function(input, output, session) {
output$dynamicui_g1 <- renderUI({
selectInput(inputId = "group1", label = "Group 1",
choices = dataOptions[!(dataOptions %in% c(input$group2, input$group3))],
multiple = TRUE)
})
output$dynamicui_g2 <- renderUI({
selectInput(inputId = "group2", label = "Group 2",
choices = dataOptions[!(dataOptions %in% c(input$group1, input$group3))],
multiple=TRUE)
})
output$dynamicui_g3 <- renderUI({
selectInput(inputId = "group3", label = "Group 3",
choices = dataOptions[!(dataOptions %in% c(input$group1, input$group2))],
multiple=TRUE)
})
}
# Run the application
shinyApp(ui = ui, server = server)