Example taken from: Filter one selectInput based on selection from another selectInput?
I am trying to create a shiny app where the user can select several boxes and then some data is generated. I dont understand if I for example click first "Mars", then the second option Candy is filtered, I would now like to select "Snickers", why does everything restore when clicking snickers?
library(shiny)
library(shinydashboard)
library(shinyWidgets)
##
ui <- shinyUI({
sidebarPanel(
htmlOutput("brand_selector"),
htmlOutput("candy_selector"))
})
##
server <- shinyServer(function(input, output) {
candyData <- read.table(
text = "Brand Candy
Nestle 100Grand
Netle Butterfinger
Nestle Crunch
Hershey's KitKat
Hershey's Reeses
Hershey's Mounds
Mars Snickers
Mars Twix
Mars M&Ms",
header = TRUE,
stringsAsFactors = FALSE)
output$brand_selector <- renderUI({
available2 <- candyData
if(NROW(input$candy) > 0 ) available2 <- candyData[candyData$Candy %in% input$candy, ]
pickerInput(
inputId = "brand",
label = "Brand:",
choices = as.character(unique(available2$Brand)),
multiple = T,options = list(`actions-box` = TRUE))
})
output$candy_selector <- renderUI({
available <- candyData
if(NROW(input$brand > 0)) available <- candyData[candyData$Brand %in% input$brand, ]
pickerInput(
inputId = "candy",
label = "Candy:",
choices = unique(available$Candy),
multiple = T,options = list(`actions-box` = TRUE))
})
})
##
shinyApp(ui = ui, server = server)