added outputArgs to all other renderXXX functions following the pattern used for renderPlot

This commit is contained in:
Barbara Borges Ribeiro
2016-03-24 00:05:51 +00:00
parent e9ab34a9c1
commit bc15b65538
9 changed files with 109 additions and 29 deletions

View File

@@ -45,6 +45,9 @@
#' This is useful if you want to save an expression in a variable.
#' @param func A function that returns an R object that can be used with
#' \code{\link[xtable]{xtable}} (deprecated; use \code{expr} instead).
#' @param outputArgs A list of arguments to be passed through to the
#' implicit call to \code{\link{tableOutput}} when \code{renderTable} is
#' used in an interactive R Markdown document.
#'
#' @export
renderTable <- function(expr, striped = FALSE, hover = FALSE,
@@ -52,7 +55,8 @@ renderTable <- function(expr, striped = FALSE, hover = FALSE,
width = "auto", align = NULL,
rownames = FALSE, colnames = TRUE,
digits = NULL, na = "NA", ...,
env = parent.frame(), quoted = FALSE, func = NULL) {
env = parent.frame(), quoted = FALSE,
func = NULL, outputArgs=list()) {
if (!is.null(func)) {
shinyDeprecated(msg = "renderTable: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
@@ -204,5 +208,5 @@ renderTable <- function(expr, striped = FALSE, hover = FALSE,
}
}
return(tab)
})
}, outputArgs = outputArgs)
}

View File

@@ -82,7 +82,9 @@ as.tags.shiny.render.function <- function(x, ..., inline = FALSE) {
#' it is sent to the client browser? Generally speaking, if the image is a
#' temp file generated within \code{func}, then this should be \code{TRUE};
#' if the image is not a temp file, this should be \code{FALSE}.
#'
#' @param outputArgs A list of arguments to be passed through to the implicit
#' call to \code{\link{imageOutput}} when \code{renderImage} is used in an
#' interactive R Markdown document.
#' @export
#'
#' @examples
@@ -140,10 +142,10 @@ as.tags.shiny.render.function <- function(x, ..., inline = FALSE) {
#'
#' }
renderImage <- function(expr, env=parent.frame(), quoted=FALSE,
deleteFile=TRUE) {
deleteFile=TRUE, outputArgs=list()) {
installExprFunction(expr, "func", env, quoted)
return(markRenderFunction(imageOutput, function(shinysession, name, ...) {
renderFunc <- function(shinysession, name, ...) {
imageinfo <- func()
# Should the file be deleted after being sent? If .deleteFile not set or if
# TRUE, then delete; otherwise don't delete.
@@ -160,7 +162,9 @@ renderImage <- function(expr, env=parent.frame(), quoted=FALSE,
# Return a list with src, and other img attributes
c(src = shinysession$fileUrl(name, file=imageinfo$src, contentType=contentType),
extra_attr)
}))
}
markRenderFunction(imageOutput, renderFunc, outputArgs = outputArgs)
}
@@ -189,6 +193,9 @@ renderImage <- function(expr, env=parent.frame(), quoted=FALSE,
#' @param func A function that may print output and/or return a printable R
#' object (deprecated; use \code{expr} instead).
#' @param width The value for \code{\link{options}('width')}.
#' @param outputArgs A list of arguments to be passed through to the implicit
#' call to \code{\link{verbatimTextOutput}} when \code{renderPrint} is used
#' in an interactive R Markdown document.
#' @seealso \code{\link{renderText}} for displaying the value returned from a
#' function, instead of the printed output.
#'
@@ -196,18 +203,20 @@ renderImage <- function(expr, env=parent.frame(), quoted=FALSE,
#'
#' @export
renderPrint <- function(expr, env = parent.frame(), quoted = FALSE, func = NULL,
width = getOption('width')) {
width = getOption('width'), outputArgs=list()) {
if (!is.null(func)) {
shinyDeprecated(msg="renderPrint: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
installExprFunction(expr, "func", env, quoted)
}
markRenderFunction(verbatimTextOutput, function() {
renderFunc <- function() {
op <- options(width = width)
on.exit(options(op), add = TRUE)
paste(utils::capture.output(func()), collapse = "\n")
})
}
markRenderFunction(verbatimTextOutput, renderFunc, outputArgs = outputArgs)
}
#' Text Output
@@ -230,6 +239,9 @@ renderPrint <- function(expr, env = parent.frame(), quoted = FALSE, func = NULL,
#' is useful if you want to save an expression in a variable.
#' @param func A function that returns an R object that can be used as an
#' argument to \code{cat}.(deprecated; use \code{expr} instead).
#' @param outputArgs A list of arguments to be passed through to the implicit
#' call to \code{\link{textOutput}} when \code{renderText} is used in an
#' interactive R Markdown document.
#'
#' @seealso \code{\link{renderPrint}} for capturing the print output of a
#' function, rather than the returned text value.
@@ -237,17 +249,20 @@ renderPrint <- function(expr, env = parent.frame(), quoted = FALSE, func = NULL,
#' @example res/text-example.R
#'
#' @export
renderText <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
renderText <- function(expr, env=parent.frame(), quoted=FALSE,
func=NULL, outputArgs=list()) {
if (!is.null(func)) {
shinyDeprecated(msg="renderText: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
installExprFunction(expr, "func", env, quoted)
}
markRenderFunction(textOutput, function() {
renderFunc <- function() {
value <- func()
return(paste(utils::capture.output(cat(value)), collapse="\n"))
})
}
markRenderFunction(textOutput, renderFunc, outputArgs = outputArgs)
}
#' UI Output
@@ -265,6 +280,9 @@ renderText <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
#' is useful if you want to save an expression in a variable.
#' @param func A function that returns a Shiny tag object, \code{\link{HTML}},
#' or a list of such objects (deprecated; use \code{expr} instead).
#' @param outputArgs A list of arguments to be passed through to the implicit
#' call to \code{\link{uiOutput}} when \code{renderUI} is used in an
#' interactive R Markdown document.
#'
#' @seealso conditionalPanel
#'
@@ -277,20 +295,35 @@ renderText <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
#' )
#' })
#' }
renderUI <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
renderUI <- function(expr, env=parent.frame(), quoted=FALSE,
func=NULL, outputArgs=list()) {
if (!is.null(func)) {
shinyDeprecated(msg="renderUI: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
installExprFunction(expr, "func", env, quoted)
}
markRenderFunction(uiOutput, function(shinysession, name, ...) {
renderFunc <- function(shinysession, name, ...) {
result <- func()
if (is.null(result) || length(result) == 0)
return(NULL)
processDeps(result, shinysession)
})
result <- takeSingletons(result, shinysession$singletons, desingleton=FALSE)$ui
result <- surroundSingletons(result)
dependencies <- lapply(resolveDependencies(findDependencies(result)),
createWebDependency)
names(dependencies) <- NULL
# renderTags returns a list with head, singletons, and html
output <- list(
html = doRenderTags(result),
deps = dependencies
)
return(output)
}
markRenderFunction(uiOutput, renderFunc, outputArgs = outputArgs)
}
#' File Downloads
@@ -316,6 +349,9 @@ renderUI <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
#' example \code{"text/csv"} or \code{"image/png"}. If \code{NULL} or
#' \code{NA}, the content type will be guessed based on the filename
#' extension, or \code{application/octet-stream} if the extension is unknown.
#' @param outputArgs A list of arguments to be passed through to the implicit
#' call to \code{\link{downloadButton}} when \code{downloadHandler} is used
#' in an interactive R Markdown document.
#'
#' @examples
#' \dontrun{
@@ -334,10 +370,11 @@ renderUI <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
#' }
#'
#' @export
downloadHandler <- function(filename, content, contentType=NA) {
return(markRenderFunction(downloadButton, function(shinysession, name, ...) {
downloadHandler <- function(filename, content, contentType=NA, outputArgs=list()) {
renderFunc <-function(shinysession, name, ...) {
shinysession$registerDownload(name, filename, contentType, content)
}))
}
markRenderFunction(downloadButton, renderFunc, outputArgs = outputArgs)
}
#' Table output with the JavaScript library DataTables
@@ -368,6 +405,10 @@ downloadHandler <- function(filename, content, contentType=NA) {
#' indicate which columns to escape, e.g. \code{1:5} (the first 5 columns),
#' \code{c(1, 3, 4)}, or \code{c(-1, -3)} (all columns except the first and
#' third), or \code{c('Species', 'Sepal.Length')}.
#' @param outputArgs A list of arguments to be passed through to the implicit
#' call to \code{\link{dataTableOutput}} when \code{renderDataTable} is used
#' in an interactive R Markdown document.
#'
#' @references \url{http://datatables.net}
#' @note This function only provides the server-side version of DataTables
#' (using R to process the data object on the server side). There is a
@@ -402,10 +443,11 @@ downloadHandler <- function(filename, content, contentType=NA) {
#' }
renderDataTable <- function(expr, options = NULL, searchDelay = 500,
callback = 'function(oTable) {}', escape = TRUE,
env = parent.frame(), quoted = FALSE) {
env = parent.frame(), quoted = FALSE,
outputArgs=list()) {
installExprFunction(expr, "func", env, quoted)
markRenderFunction(dataTableOutput, function(shinysession, name, ...) {
renderFunc <- function(shinysession, name, ...) {
if (is.function(options)) options <- options()
options <- checkDT9(options)
res <- checkAsIs(options)
@@ -431,7 +473,9 @@ renderDataTable <- function(expr, options = NULL, searchDelay = 500,
evalOptions = if (length(res$eval)) I(res$eval), searchDelay = searchDelay,
callback = paste(callback, collapse = '\n'), escape = escape
)
})
}
markRenderFunction(dataTableOutput, renderFunc, outputArgs = outputArgs)
}
# a data frame containing the DataTables 1.9 and 1.10 names

View File

@@ -4,7 +4,7 @@
\alias{downloadHandler}
\title{File Downloads}
\usage{
downloadHandler(filename, content, contentType = NA)
downloadHandler(filename, content, contentType = NA, outputArgs = list())
}
\arguments{
\item{filename}{A string of the filename, including extension, that the
@@ -22,6 +22,10 @@ function.)}
example \code{"text/csv"} or \code{"image/png"}. If \code{NULL} or
\code{NA}, the content type will be guessed based on the filename
extension, or \code{application/octet-stream} if the extension is unknown.}
\item{outputArgs}{A list of arguments to be passed through to the implicit
call to \code{\link{downloadButton}} when \code{downloadHandler} is used
in an interactive R Markdown document.}
}
\description{
Allows content from the Shiny application to be made available to the user as

View File

@@ -6,7 +6,7 @@
\usage{
renderDataTable(expr, options = NULL, searchDelay = 500,
callback = "function(oTable) {}", escape = TRUE, env = parent.frame(),
quoted = FALSE)
quoted = FALSE, outputArgs = list())
}
\arguments{
\item{expr}{An expression that returns a data frame or a matrix.}
@@ -32,6 +32,10 @@ third), or \code{c('Species', 'Sepal.Length')}.}
\item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This
is useful if you want to save an expression in a variable.}
\item{outputArgs}{A list of arguments to be passed through to the implicit
call to \code{\link{dataTableOutput}} when \code{renderDataTable} is used
in an interactive R Markdown document.}
}
\description{
Makes a reactive version of the given function that returns a data frame (or

View File

@@ -4,7 +4,8 @@
\alias{renderImage}
\title{Image file output}
\usage{
renderImage(expr, env = parent.frame(), quoted = FALSE, deleteFile = TRUE)
renderImage(expr, env = parent.frame(), quoted = FALSE, deleteFile = TRUE,
outputArgs = list())
}
\arguments{
\item{expr}{An expression that returns a list.}
@@ -18,6 +19,10 @@ is useful if you want to save an expression in a variable.}
it is sent to the client browser? Generally speaking, if the image is a
temp file generated within \code{func}, then this should be \code{TRUE};
if the image is not a temp file, this should be \code{FALSE}.}
\item{outputArgs}{A list of arguments to be passed through to the implicit
call to \code{\link{imageOutput}} when \code{renderImage} is used in an
interactive R Markdown document.}
}
\description{
Renders a reactive image that is suitable for assigning to an \code{output}

View File

@@ -5,7 +5,7 @@
\title{Printable Output}
\usage{
renderPrint(expr, env = parent.frame(), quoted = FALSE, func = NULL,
width = getOption("width"))
width = getOption("width"), outputArgs = list())
}
\arguments{
\item{expr}{An expression that may print output and/or return a printable R
@@ -19,6 +19,10 @@ object.}
object (deprecated; use \code{expr} instead).}
\item{width}{The value for \code{\link{options}('width')}.}
\item{outputArgs}{A list of arguments to be passed through to the implicit
call to \code{\link{verbatimTextOutput}} when \code{renderPrint} is used
in an interactive R Markdown document.}
}
\description{
Makes a reactive version of the given function that captures any printed

View File

@@ -7,7 +7,8 @@
renderTable(expr, striped = FALSE, hover = FALSE, bordered = FALSE,
spacing = c("s", "xs", "m", "l"), width = "auto", align = NULL,
rownames = FALSE, colnames = TRUE, digits = NULL, na = "NA", ...,
env = parent.frame(), quoted = FALSE, func = NULL)
env = parent.frame(), quoted = FALSE, func = NULL,
outputArgs = list())
}
\arguments{
\item{expr}{An expression that returns an R object that can be used with
@@ -60,6 +61,10 @@ This is useful if you want to save an expression in a variable.}
\item{func}{A function that returns an R object that can be used with
\code{\link[xtable]{xtable}} (deprecated; use \code{expr} instead).}
\item{outputArgs}{A list of arguments to be passed through to the
implicit call to \code{\link{tableOutput}} when \code{renderTable} is
used in an interactive R Markdown document.}
}
\description{
Creates a reactive table that is suitable for assigning to an \code{output}

View File

@@ -4,7 +4,8 @@
\alias{renderText}
\title{Text Output}
\usage{
renderText(expr, env = parent.frame(), quoted = FALSE, func = NULL)
renderText(expr, env = parent.frame(), quoted = FALSE, func = NULL,
outputArgs = list())
}
\arguments{
\item{expr}{An expression that returns an R object that can be used as an
@@ -17,6 +18,10 @@ is useful if you want to save an expression in a variable.}
\item{func}{A function that returns an R object that can be used as an
argument to \code{cat}.(deprecated; use \code{expr} instead).}
\item{outputArgs}{A list of arguments to be passed through to the implicit
call to \code{\link{textOutput}} when \code{renderText} is used in an
interactive R Markdown document.}
}
\description{
Makes a reactive version of the given function that also uses

View File

@@ -4,7 +4,8 @@
\alias{renderUI}
\title{UI Output}
\usage{
renderUI(expr, env = parent.frame(), quoted = FALSE, func = NULL)
renderUI(expr, env = parent.frame(), quoted = FALSE, func = NULL,
outputArgs = list())
}
\arguments{
\item{expr}{An expression that returns a Shiny tag object, \code{\link{HTML}},
@@ -17,6 +18,10 @@ is useful if you want to save an expression in a variable.}
\item{func}{A function that returns a Shiny tag object, \code{\link{HTML}},
or a list of such objects (deprecated; use \code{expr} instead).}
\item{outputArgs}{A list of arguments to be passed through to the implicit
call to \code{\link{uiOutput}} when \code{renderUI} is used in an
interactive R Markdown document.}
}
\description{
\bold{Experimental feature.} Makes a reactive version of a function that