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
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)
.
# 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 = ",")
})