4

Given pseduo-like code:

dateRange <- reactive({
    input$select_dates #action button

    save_selected_date_range()
    isolate(input$dateRange)
})


customerId <- reactive({
    #check if customer has saved date range if so trigger
    saved_info <- saved_preferences(input$customerId)
    if(nrow(saved_info) > 0) {
      flog.info(saved_info)
      updateDateRangeInput(session, "dateRange", start = saved_info$start, end = saved_info$start)
    }

    input$customerId
})

The scenario:

Inputs: A selected date range and customer selector. The date range is registered when the action button is pressed.

Desired Action: We would like the ability to load saved date ranges if available when a customer is picked.

Question: How do I trigger the input$select_dates as if the action button was pushed? Something like invalidateLater without the timer would be nice. Or if there is a manual way to mark or flag the input$select_dates as invalidated.

lapolonio
  • 1,107
  • 2
  • 14
  • 24

1 Answers1

12

Define a reactive value

rv <- reactiveValues( v = 0)

put it inside your reactive expression

dateRange <- reactive({
    rv$v
    input$select_dates #action button

    save_selected_date_range()
    isolate(input$dateRange)
})

just change the value of rv$v (like rv$v <- rv$v + 1) in any part of your code and the dateRage expression will be invalidated.

Geovany
  • 5,389
  • 21
  • 37