Previous input in Shiny

后端 未结 1 826
渐次进展
渐次进展 2020-12-21 23:40

How to retain previous input in Shiny?

I want to show how estimates change according to user input.

E.g., If user changes input and an estimate is up, then i

相关标签:
1条回答
  • 2020-12-22 00:08

    You could store the previous and actual values inside a reactiveValues object:

    rv$prev_bins is initialized as NULL, then on every value change, the new value is appended to the vector.

    To keep only the previous and current values instead of all, use: rv$prev_bins <- c(tail(rv$prev_bins, 1), input$bins).

    Code:

    # Initialize reactive values
    rv <- reactiveValues(prev_bins = NULL)
    
    # Append new value to previous values when input$bins changes 
    observeEvent(input$bins, {
      rv$prev_bins <- c(rv$prev_bins, input$bins)
    })
    
    # Output
    output$print <- renderPrint({
      paste(rv$prev_bins, collapse = ",")
    })
    

    Output:

    0 讨论(0)
提交回复
热议问题