...
Hi,
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:
-
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.
-
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:
library(shiny)
library(tidyverse)
library(dplyr)
library(DT)
library(leaflet)
masterdb <- read_csv("https://raw.githubusercontent.com/dexterpante/nspp/main/masterdb.csv")
ui <- fluidPage(
# Application title
titlePanel("New School Personnel Position Dashboard"),
sidebarLayout(
sidebarPanel(
selectInput("ROID", "Select Region",
choices = sort(masterdb$Region),
multiple = F),
uiOutput("SDOID"),
checkboxGroupInput("LEVELID", "Select the Level of Education",
choices = c("ES", "JHS", "SHS")),
actionButton('action', 'Search')
),
# Show output
mainPanel(
#leafletOutput("nsppmap"),
DTOutput("nspptable")
)
)
)
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, {
req(input$ROID)
req(input$SDO_input)
req(input$LEVELID)
myfilter()
})
# 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?