I am trying to use each values selected in a pickerInput control in r shiny app. I have a sample code as follows:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
pickerInput(inputId = "testPicker",
label = "Select Multiple",
choices = c(2021, 2020,2019,2018,2017),
selected = c(2021, 2020,2019,2018,2017),
multiple = TRUE,
options = list(
`actions-box` = TRUE,
"max-options" = 4,
"max-options-text" = "You can ONLY select 4 years!"
)),
verbatimTextOutput("year1"),
verbatimTextOutput("year2")
verbatimTextOutput("year3")
)
server <- function(input, output, session) {
output$year1 <- renderPrint(input$testPicker[3])
output$year2 <- renderPrint(input$testPicker[2])
output$year3 <- renderPrint(input$testPicker[1])
}
shinyApp(ui, server)
I was expecting this code above to work but it is not printing any values. I want to use each selected value in a search to get a different data frame like this:
total_for_year1 <- main_data() %>%
filter(Year == input$testPicker[4]) %>%
group_by(LGA) %>%
summarise("Total Students" = sum(`Class Student Count`)) %>%
ungroup()
The data I am using can be downloaded from https://github.com/BAderinto/rshiny_data/blob/main/df.csv I needed the user to select multiple years, then I use each of the values to filter and return a data frame each for each year selected.
Any suggestion?