EVOLUTION-MANAGER
Edit File: reactiveVal.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Create a (single) reactive value</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for reactiveVal {shiny}"><tr><td>reactiveVal {shiny}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Create a (single) reactive value</h2> <h3>Description</h3> <p>The <code>reactiveVal</code> function is used to construct a "reactive value" object. This is an object used for reading and writing a value, like a variable, but with special capabilities for reactive programming. When you read the value out of a reactiveVal object, the calling reactive expression takes a dependency, and when you change the value, it notifies any reactives that previously depended on that value. </p> <h3>Usage</h3> <pre> reactiveVal(value = NULL, label = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>value</code></td> <td> <p>An optional initial value.</p> </td></tr> <tr valign="top"><td><code>label</code></td> <td> <p>An optional label, for debugging purposes (see <code><a href="reactlog.html">reactlog()</a></code>). If missing, a label will be automatically created.</p> </td></tr> </table> <h3>Details</h3> <p><code>reactiveVal</code> is very similar to <code><a href="reactiveValues.html">reactiveValues()</a></code>, except that the former is for a single reactive value (like a variable), whereas the latter lets you conveniently use multiple reactive values by name (like a named list of variables). For a one-off reactive value, it's more natural to use <code>reactiveVal</code>. See the Examples section for an illustration. </p> <h3>Value</h3> <p>A function. Call the function with no arguments to (reactively) read the value; call the function with a single argument to set the value. </p> <h3>Examples</h3> <pre> ## Not run: # Create the object by calling reactiveVal r <- reactiveVal() # Set the value by calling with an argument r(10) # Read the value by calling without arguments r() ## End(Not run) ## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( actionButton("minus", "-1"), actionButton("plus", "+1"), br(), textOutput("value") ) # The comments below show the equivalent logic using reactiveValues() server <- function(input, output, session) { value <- reactiveVal(0) # rv <- reactiveValues(value = 0) observeEvent(input$minus, { newValue <- value() - 1 # newValue <- rv$value - 1 value(newValue) # rv$value <- newValue }) observeEvent(input$plus, { newValue <- value() + 1 # newValue <- rv$value + 1 value(newValue) # rv$value <- newValue }) output$value <- renderText({ value() # rv$value }) } shinyApp(ui, server) } </pre> <hr /><div style="text-align: center;">[Package <em>shiny</em> version 1.5.0 <a href="00Index.html">Index</a>]</div> </body></html>