library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
numericInput("year", "year", value = 2020),
dateInput("date", "Date")
)
server <- function(input, output, session) {
observeEvent(input$year, {
req(isTruthy(input$year)) # stop if year is blank
daterange <- range(as.Date(paste0(input$year, "-01-01")),as.Date(paste0(input$year, "-12-31")))
updateDateInput(session, "date", min = daterange[1], max = daterange[2] )
delay(250, # delay 250ms
updateDateInput(session,"date",
value = daterange[1]
))
})
}
shinyApp(ui = ui, server = server)
I want to use updateDateInput where the user is limited to the year selected in a numericInput. I was trying to follow the tutorial here: https://shiny.rstudio.com/reference/shiny/0.14/updateDateInput.html but the demo doesn't seem to be working 😬
Based on this community post I ended up using a delay https://community.rstudio.com/t/updatedateinput-based-on-another-dateinput-issue-in-shiny/55477 and this worked - but I figured the Shiny team may want this on their radar? Thank you!!
This works but seems a little convoluted