Hierarchical SelectInput and Checkbox in Shiny do not show correct data output

I am still new to shiny so please forgive me for these questions.
I am making an shiny app that will show the the teacher shortage and excess per schoolname, by level of education (Elementary or ES, Junior High School or JHS, and Senior High School or SHS), Division and Region (which are grouping variables).

The app has 3 controls: 2 SelectInputs and 1 CheckboxGroupInput.
The 2 selectinputs are linked such that when you select a Region via the first SelectInput, the second SelectInput entry changes based on the Region selected.

The CheckboxGroupInput is independent from the 2 SelectInputs.

The problems here are the following:

  1. When the second selectinput has two values (because multiple=TRUE), the output table does not show all the schools from the two values. See Picture 1.

  2. Individual checking of checkboxGroupInput is working but when 2 or more choices are checked, the data table does not show all schools that meet the checked parameters in the checkboxGroupInput. See Picture 2.

Here's the code:

masterdb <- read_csv("https://raw.githubusercontent.com/dexterpante/nspp/main/masterdb.csv")

ui <- fluidPage(

# Application title
titlePanel("New School Personnel Position Dashboard"),

        selectInput("ROID", "Select Region", 
                    choices = sort(masterdb$Region),
                    multiple = F),
        checkboxGroupInput("LEVELID", "Select the Level of Education",
                           choices = c("ES", "JHS", "SHS")),
        actionButton('action', 'Search')

    # Show output


server <- function(input, output, session) {

# render the car selection input
output$SDOID <- renderUI({
    selectInput("SDO_input", "Select the Division Office",
                choices = masterdb %>% filter (Region==input$ROID) %>% select(Division),
        multiple = T)

myfilter <- reactive({
  masterdb %>% 
    filter(Region==input$ROID & Division==input$SDO_input & Level==input$LEVELID) %>%
    select(Region, Division, Level, SchoolName, Excess, Shortage)
# update the table data when the action button is clicked
table_data <- eventReactive(input$action, {

# render the table data
output$nspptable <- renderDT(table_data())


shinyApp(ui, server)

What seems to be incorrect in my server code that the right answer is not showing?

Hi @dnpante. Since your second selectInput allows multiple selections, your filter should use "%in%" instead of "==".

myfilter <- reactive({
    masterdb %>% 
      filter(Region==input$ROID & Division %in% input$SDO_input & Level==input$LEVELID) %>%
      select(Region, Division, Level, SchoolName, Excess, Shortage)

Thank you so much! It solves both problem.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.