From deb56539fbf458f73630161431767cced0ca5003 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Tue, 25 Apr 2017 10:48:29 -0500 Subject: [PATCH] Better reactivePoll example. Closes #1678 --- R/reactives.R | 17 +++++++++++++++-- man/reactivePoll.Rd | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/R/reactives.R b/R/reactives.R index c41948e6f..53bddcadc 100644 --- a/R/reactives.R +++ b/R/reactives.R @@ -1541,9 +1541,22 @@ coerceToFunc <- function(x) { #' @seealso \code{\link{reactiveFileReader}} #' #' @examples -#' # Assume the existence of readTimestamp and readValue functions #' function(input, output, session) { -#' data <- reactivePoll(1000, session, readTimestamp, readValue) +#' +#' 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() #' }) diff --git a/man/reactivePoll.Rd b/man/reactivePoll.Rd index 9f2602281..daa2f335a 100644 --- a/man/reactivePoll.Rd +++ b/man/reactivePoll.Rd @@ -57,9 +57,22 @@ will be executed in a reactive context; therefore, they may read reactive values and reactive expressions. } \examples{ -# Assume the existence of readTimestamp and readValue functions function(input, output, session) { - data <- reactivePoll(1000, session, readTimestamp, readValue) + + 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() })