-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
reactiveFileReader.Rd
71 lines (64 loc) · 2.29 KB
/
reactiveFileReader.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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reactives.R
\name{reactiveFileReader}
\alias{reactiveFileReader}
\title{Reactive file reader}
\usage{
reactiveFileReader(intervalMillis, session, filePath, readFunc, ...)
}
\arguments{
\item{intervalMillis}{Approximate number of milliseconds to wait between
checks of the file's last modified time. This can be 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{filePath}{The file path to poll against and to pass to \code{readFunc}.
This can either be a single-element character vector, or a function that
returns one.}
\item{readFunc}{The function to use to read the file; must expect the first
argument to be the file path to read. The return value of this function is
used as the value of the reactive file reader.}
\item{...}{Any additional arguments to pass to \code{readFunc} whenever it is
invoked.}
}
\value{
A reactive expression that returns the contents of the file, and
automatically invalidates when the file changes on disk (as determined by
last modified time).
}
\description{
Given a file path and read function, returns a reactive data source for the
contents of the file.
}
\details{
\code{reactiveFileReader} works by periodically checking the file's last
modified time; if it has changed, then the file is re-read and any reactive
dependents are invalidated.
The \code{intervalMillis}, \code{filePath}, and \code{readFunc} functions
will each be executed in a reactive context; therefore, they may read
reactive values and reactive expressions.
}
\examples{
\dontrun{
# Per-session reactive file reader
function(input, output, session) {
fileData <- reactiveFileReader(1000, session, 'data.csv', read.csv)
output$data <- renderTable({
fileData()
})
}
# Cross-session reactive file reader. In this example, all sessions share
# the same reader, so read.csv only gets executed once no matter how many
# user sessions are connected.
fileData <- reactiveFileReader(1000, NULL, 'data.csv', read.csv)
function(input, output, session) {
output$data <- renderTable({
fileData()
})
}
}
}
\seealso{
\code{\link[=reactivePoll]{reactivePoll()}}
}