forked from rstudio/shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactive.Rd
66 lines (55 loc) · 2.11 KB
/
reactive.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{reactive}
\alias{is.reactive}
\alias{reactive}
\title{Create a reactive expression}
\usage{
reactive(x, env = parent.frame(), quoted = FALSE, label = NULL,
domain = getDefaultReactiveDomain())
is.reactive(x)
}
\arguments{
\item{x}{For \code{reactive}, an expression (quoted or unquoted). For
\code{is.reactive}, an object to test.}
\item{env}{The parent environment for the reactive expression. By default, this
is the calling environment, the same as when defining an ordinary
non-reactive expression.}
\item{quoted}{Is the expression quoted? By default, this is \code{FALSE}.
This is useful when you want to use an expression that is stored in a
variable; to do so, it must be quoted with `quote()`.}
\item{label}{A label for the reactive expression, useful for debugging.}
\item{domain}{See \link{domains}.}
}
\value{
a function, wrapped in a S3 class "reactive"
}
\description{
Wraps a normal expression to create a reactive expression. Conceptually, a
reactive expression is a expression whose result will change over time.
}
\details{
Reactive expressions are expressions that can read reactive values and call other
reactive expressions. Whenever a reactive value changes, any reactive expressions
that depended on it are marked as "invalidated" and will automatically
re-execute if necessary. If a reactive expression is marked as invalidated, any
other reactive expressions that recently called it are also marked as
invalidated. In this way, invalidations ripple through the expressions that
depend on each other.
See the \href{http://rstudio.github.com/shiny/tutorial/}{Shiny tutorial} for
more information about reactive expressions.
}
\examples{
values <- reactiveValues(A=1)
reactiveB <- reactive({
values$A + 1
})
# Can use quoted expressions
reactiveC <- reactive(quote({ values$A + 2 }), quoted = TRUE)
# To store expressions for later conversion to reactive, use quote()
expr_q <- quote({ values$A + 3 })
reactiveD <- reactive(expr_q, quoted = TRUE)
# View the values from the R console with isolate()
isolate(reactiveB())
isolate(reactiveC())
isolate(reactiveD())
}