-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
reactivePoll.Rd
83 lines (74 loc) · 2.86 KB
/
reactivePoll.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reactives.R
\name{reactivePoll}
\alias{reactivePoll}
\title{Reactive polling}
\usage{
reactivePoll(intervalMillis, session, checkFunc, valueFunc)
}
\arguments{
\item{intervalMillis}{Approximate number of milliseconds to wait between
calls to \code{checkFunc}. This can be either a numeric value, or a
function that returns a numeric value.}
\item{session}{The user session to associate this file reader with, or
\code{NULL} if none. If non-null, the reader will automatically stop when
the session ends.}
\item{checkFunc}{A relatively cheap function whose values over time will be
tested for equality; inequality indicates that the underlying value has
changed and needs to be invalidated and re-read using \code{valueFunc}. See
Details.}
\item{valueFunc}{A function that calculates the underlying value. See
Details.}
}
\value{
A reactive expression that returns the result of \code{valueFunc},
and invalidates when \code{checkFunc} changes.
}
\description{
Used to create a reactive data source, which works by periodically polling a
non-reactive data source.
}
\details{
\code{reactivePoll} works by pairing a relatively cheap "check" function with
a more expensive value retrieval function. The check function will be
executed periodically and should always return a consistent value until the
data changes. When the check function returns a different value, then the
value retrieval function will be used to re-populate the data.
Note that the check function doesn't return \code{TRUE} or \code{FALSE} to
indicate whether the underlying data has changed. Rather, the check function
indicates change by returning a different value from the previous time it was
called.
For example, \code{reactivePoll} is used to implement
\code{reactiveFileReader} by pairing a check function that simply returns the
last modified timestamp of a file, and a value retrieval function that
actually reads the contents of the file.
As another example, one might read a relational database table reactively by
using a check function that does \verb{SELECT MAX(timestamp) FROM table} and
a value retrieval function that does \verb{SELECT * FROM table}.
The \code{intervalMillis}, \code{checkFunc}, and \code{valueFunc} functions
will be executed in a reactive context; therefore, they may read reactive
values and reactive expressions.
}
\examples{
function(input, output, session) {
data <- reactivePoll(1000, session,
# This function returns the time that log_file was last modified
checkFunc = function() {
if (file.exists(log_file))
file.info(log_file)$mtime[1]
else
""
},
# This function returns the content of log_file
valueFunc = function() {
read.csv(log_file)
}
)
output$dataTable <- renderTable({
data()
})
}
}
\seealso{
\code{\link[=reactiveFileReader]{reactiveFileReader()}}
}