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

Mention how to freeze inputs #293

Closed
hadley opened this issue Oct 29, 2020 · 4 comments
Closed

Mention how to freeze inputs #293

hadley opened this issue Oct 29, 2020 · 4 comments

Comments

@hadley
Copy link
Owner

hadley commented Oct 29, 2020

rstudio/shiny#3055

@hadley
Copy link
Owner Author

hadley commented Nov 9, 2020

@hadley
Copy link
Owner Author

hadley commented Feb 10, 2021

@malcolmbarrett
Copy link
Contributor

Oh, that would be great to add. I didn't know about this.

@hadley
Copy link
Owner Author

hadley commented Feb 23, 2021

In

ui <- fluidPage(
  dateInput("date", "choose a date"), 
  selectInput("year", "Choose a year", choices = 2010:2030)
)

server <- function(input, output, session) {
  observeEvent(input$date, {
    year <- format(input$date, "%Y")
    message("Changing year to ", year)
    updateSelectInput(inputId = "year", selected = year)
  })
  
  observeEvent(input$year, {
    date <- as.Date(ISOdate(input$year, 1, 1))
    message("Changing date to ", date)
    updateDateInput(inputId = "date", value = date)
  })
}

The key problem is that all updates processed by the browser in a single batch, after all observers have completed. This means that it since it starts in an inconsistent state it rapidly toggles back and forward. The easiest fix is to just set selected = 2021.

@hadley hadley closed this as completed in 9e34701 Feb 23, 2021
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

2 participants