I'm making an interactive R Shiny dashboard and I am trying to implement functionality to select a view(Day, Week, Month, Year) and select a starting and ending date value using this code:
observeEvent(input$idCasesDateType, {
cat('View Selection changed!\nSelected - ', input$idCasesDateType, '\n')
switch(
input$idCasesDateType,
'Daily' = {
data <- GetDateData(cases_C, 'day')
updateDateInput(session, 'minDate_Cases', max = max(data$Date) - 6)
updateDateInput(session, 'minDate_Cases', value = min(data$Date))
updateDateInput(session, 'maxDate_Cases', min = min(data$Date) + 6)
updateDateInput(session, 'maxDate_Cases', value = max(data$Date))
},
'Weekly' = {
data <- GetDateData(cases_C, 'week')
updateDateInput(session, 'minDate_Cases', max = max(data$Date) - 34)
updateDateInput(session, 'minDate_Cases', value = min(data$Date))
updateDateInput(session, 'maxDate_Cases', min = min(data$Date) + 34)
updateDateInput(session, 'maxDate_Cases', value = max(data$Date))
},
'Monthly' = {
data <- GetDateData(cases_C, 'month')
updateDateInput(session, 'minDate_Cases', max = max(data$Date) %m-% months(5))
updateDateInput(session, 'minDate_Cases', value = min(data$Date))
updateDateInput(session, 'maxDate_Cases', min = min(data$Date) %m+% months(5))
updateDateInput(session, 'maxDate_Cases', value = max(data$Date))
},
'Yearly' = {
updateDateInput(session, 'minDate_Cases', value = min(cases_C$Date))
updateDateInput(session, 'maxDate_Cases', value = max(cases_C$Date))
# Disable the input - user cannot select input for the year view
shinyjs::disable('maxDate_Cases')
}
)
cat(input$minDate_Cases, ' - ', min(data$Date), '\n')
cat(input$maxDate_Cases, ' - ', max(data$Date), '\n')
})
The cat
statements are what I am trying to use to debug currently because when this section of code executes for the first time, the values of my two reactive values(input$minDate_Cases and input$maxDate_Cases) is empty even though I set them. I get this as my output:
View Selection changed!
Selected - Daily
- 18331
- 19155
and on subsequent runs when choosing a different view I get:
View Selection changed!
Selected - Monthly
18331 - 18322
19155 - 19144
This shows that I do have valid data that I am trying to set the values to but they are not being set here and are not being updated when I change the selected view.