Learn R Programming

rewind (version 0.3.0)

rewind_diff: Show what changed between two steps

Description

rewind_history() gives one row for each step, with a label such as "region, year". That label says which values changed. This function gives the values themselves: what each one held before, and what it holds now.

Usage

rewind_diff(
  from = NULL,
  to = NULL,
  session = shiny::getDefaultReactiveDomain()
)

Value

A data frame with one row for each value that differs, in the order of the names. It has six columns:

  • from, to: the two positions compared.

  • name: the input ID, or id$field for a tracked value.

  • change: a short description that a person can read.

  • old, new: list columns that hold the values themselves.

The data frame has no rows when nothing differs, and when there is no earlier step to compare with. It depends on the history, so you can use it in render*() and observe().

Arguments

from, to

The two positions to compare, as in the index column of rewind_history(). The default compares the current position with the one before it. Give both to compare any two positions.

session

The Shiny session. The default is the current session.

This is not an audit trail

The history lives in the memory of one session, and it goes when the session goes. It also drops the oldest entries when it passes depth, and it drops the steps in front of the position when a change arrives after an undo. A record for an inspection must be written as each change occurs, and kept somewhere else. The history is reactive, so:

observeEvent(rewind_history(), {
  write_my_audit_row(rewind_diff())
})

Names, and not labels

The name column holds the input ID, such as region. It does not hold the label of the widget, because Shiny does not give the server the label of an input. A value that rewind_track() records appears as id$field.

The values can be any type

old and new are list columns, so they hold the values themselves, whatever their type. The change column is a short description for a person to read. It shows both values when they are short, such as "North -> South", and a count when they are not, such as "12 values".

Details

Use it to tell the user what an undo will do, or to write your own record of what a person changed.

Examples

Run this code
if (interactive()) {
  library(shiny)

  ui <- fluidPage(
    rewind_buttons(),
    selectInput("region", "Region", c("North", "South", "East")),
    sliderInput("year", "Years", 2018, 2026, c(2018, 2026), sep = ""),
    tableOutput("changed")
  )

  server <- function(input, output, session) {
    rewind_enable()

    # What did the last step change?
    output$changed <- renderTable({
      rewind_diff()[, c("name", "change")]
    })
  }

  shinyApp(ui, server)
}

Run the code above in your browser using DataLab