You can update the selectize control based on the selection of the other control
library(shiny)
library(dplyr)
# Sample data
ASData <- data.frame(stringsAsFactors = FALSE,
LA = c(rep("A", 5), rep("B", 5)),
School = sample(letters, 10))
# Define UI for application that draws a histogram
ui <- fluidPage(
titlePanel("Reprex"),
sidebarLayout(
sidebarPanel(
selectizeInput("LASelect",
label = "Filter by Area:",
selected = "",
choices = c(ASData %>%
filter(!is.na(LA)) %>%
select(LA) %>%
unique() %>%
arrange(LA) %>%
.$LA),
multiple = FALSE),
selectizeInput("SchoolSelect",
label = "Filter by School:",
selected = "A Primary School",
choices = c(ASData %>%
filter(!is.na(School)) %>%
select(School) %>%
unique() %>%
arrange(School)),
multiple = TRUE)),
mainPanel(
)
)
)
server <- function(input, output, session) {
observeEvent(input$LASelect, {
updateSelectizeInput(session,
inputId = "SchoolSelect",
choices = c(ASData %>%
filter(!is.na(School), LA == input$LASelect) %>%
select(School) %>%
unique() %>%
arrange(School)))
})
}
shinyApp(ui = ui, server = server)