Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateDateInput requires shinyjs to work? #2798

Closed
MayaGans opened this issue Mar 19, 2020 · 2 comments
Closed

updateDateInput requires shinyjs to work? #2798

MayaGans opened this issue Mar 19, 2020 · 2 comments

Comments

@MayaGans
Copy link

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

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)
@daattali
Copy link
Contributor

daattali commented Jun 7, 2020

I think even a delay of 0 would work as a hacky workaround. I believe this is most likely a duplicate of #2703

@cpsievert
Copy link
Collaborator

Yes, this is a duplicate of #2703

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants