Hi,
I have a dataset for making shiny app for monitoring schools. The filters are as follows:
- Trainer
- Teachers who come under the trainer selected above.
- Relevant schools which come under the selected teachers.
- Relevant weeks that have been monitored.
But I want flexibility such that I can select the schools after selecting the trainer (basically filter 1 and 3 bypassing the 2nd filter). For example, if I have an output that depends on 1st and 3rd filter, I will select these and see the output. In my observe function, earlier I had used &
and now I changed it to |
, but still it doesn't work. How can I solve this?
library(shiny)
library(tidyverse)
library(janitor)
#>
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#>
#> chisq.test, fisher.test
library(shinydashboard)
#>
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
data<-tibble::tribble(
~master, ~teacher, ~school, ~week,
"Madhumathi", "Nithin", "GHPS KUSUGAL", 3L,
"Nagma", "Prathibha", "GHPS UNKAL", 1L,
"Anil", "Mrigank", "GLPS TADAKOD", 1L,
"Madhumathi", "Girish", "GHPS VIDYA", 3L,
"Nagma", "Akshay", "GHPS KALLE", 1L,
"Anil", "Ganesh", "GLPS NOOLVI", 1L,
"Madhumathi", "Chintu", "HPS YARIKOPPA", 2L,
"Nagma", "Freddy", "GHPS SHEREWAD", 2L,
"Anil", "Derek", "GHPS YADAWAD", 3L,
"Madhumathi", "Navin", "GHPS KURUBAGATTI", 2L,
"Nagma", "Jaya", "GLPS SULLA", 2L,
"Anil", "Obama", "GLPS BYAHATTI", 2L
)
ui<-dashboardPage(
skin = "red",
dashboardHeader(title = "EarlySpark MIS Dashboard 2022-23",titleWidth = 550),
dashboardSidebar("Choose your inputs here",
selectInput("master","Select the Master Trainer",choices=unique(data$master),multiple=T),
selectInput("teacher","Select the Teacher",choices = NULL,multiple = T),
selectInput("school","Select the School",choices = NULL,multiple = T),
selectInput("week","Select the Week number", choices = NULL,multiple = T)),
dashboardBody(
tabsetPanel(
tabPanel(title = "first"
)
)
)
)
server<-function(input,output,session){
observe({
req(input$master)
x<-data %>%
filter(master %in% input$master) %>%
select(teacher)
updateSelectInput(session,"teacher","Select the Teacher",choices = c("All",x))
})
observe({
req(input$master)
req(input$teacher)
y<-data %>%
filter(mastert%in% input$master | teacher %in% input$teacher) %>%
select(school)
updateSelectInput(session,"school","Select the School",choices = c("All",y))
})
observe({
req(input$master)
req(input$teacher)
req(input$school)
z<-data %>%
filter(mastertraid %in% input$master |
en_name %in% input$instructor |
schoolid %in% input$school) %>%
select(week)
updateSelectInput(session,"week","Select the Week number",choices = c("All",z))
})
}
shinyApp(ui,server)
#> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.
Shiny applications not supported in static R Markdown documents
Created on 2022-09-20 by the reprex package (v2.0.1)