| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/reactives.R |
| 3 |
\name{reactiveFileReader} |
| 4 |
\alias{reactiveFileReader} |
| 5 |
\title{Reactive file reader} |
| 6 |
\usage{ |
| 7 |
reactiveFileReader(intervalMillis, session, filePath, readFunc, ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{intervalMillis}{Approximate number of milliseconds to wait between |
| 11 |
checks of the file's last modified time. This can be a numeric value, or a |
| 12 |
function that returns a numeric value.} |
| 13 |
|
| 14 |
\item{session}{The user session to associate this file reader with, or |
| 15 |
\code{NULL} if none. If non-null, the reader will automatically stop when |
| 16 |
the session ends.} |
| 17 |
|
| 18 |
\item{filePath}{The file path to poll against and to pass to \code{readFunc}. |
| 19 |
This can either be a single-element character vector, or a function that |
| 20 |
returns one.} |
| 21 |
|
| 22 |
\item{readFunc}{The function to use to read the file; must expect the first |
| 23 |
argument to be the file path to read. The return value of this function is |
| 24 |
used as the value of the reactive file reader.} |
| 25 |
|
| 26 |
\item{...}{Any additional arguments to pass to \code{readFunc} whenever it is |
| 27 |
invoked.} |
| 28 |
} |
| 29 |
\value{ |
| 30 |
A reactive expression that returns the contents of the file, and |
| 31 |
automatically invalidates when the file changes on disk (as determined by |
| 32 |
last modified time). |
| 33 |
} |
| 34 |
\description{ |
| 35 |
Given a file path and read function, returns a reactive data source for the |
| 36 |
contents of the file. |
| 37 |
} |
| 38 |
\details{ |
| 39 |
\code{reactiveFileReader} works by periodically checking the file's last |
| 40 |
modified time; if it has changed, then the file is re-read and any reactive |
| 41 |
dependents are invalidated. |
| 42 |
|
| 43 |
The \code{intervalMillis}, \code{filePath}, and \code{readFunc} functions |
| 44 |
will each be executed in a reactive context; therefore, they may read |
| 45 |
reactive values and reactive expressions. |
| 46 |
} |
| 47 |
\examples{ |
| 48 |
\dontrun{ |
| 49 |
# Per-session reactive file reader |
| 50 |
function(input, output, session) { |
| 51 |
fileData <- reactiveFileReader(1000, session, 'data.csv', read.csv) |
| 52 |
|
| 53 |
output$data <- renderTable({ |
| 54 |
fileData() |
| 55 |
}) |
| 56 |
} |
| 57 |
|
| 58 |
# Cross-session reactive file reader. In this example, all sessions share |
| 59 |
# the same reader, so read.csv only gets executed once no matter how many |
| 60 |
# user sessions are connected. |
| 61 |
fileData <- reactiveFileReader(1000, NULL, 'data.csv', read.csv) |
| 62 |
function(input, output, session) { |
| 63 |
output$data <- renderTable({ |
| 64 |
fileData() |
| 65 |
}) |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
\seealso{ |
| 70 |
\code{\link[=reactivePoll]{reactivePoll()}} |
| 71 |
} |