add a 'width' argument so we can control the width of the text output

This commit is contained in:
Yihui Xie
2014-05-16 14:17:50 -05:00
parent a42f046ff8
commit 9d8d04ae28
2 changed files with 10 additions and 4 deletions

View File

@@ -353,14 +353,15 @@ renderTable <- function(expr, ..., env=parent.frame(), quoted=FALSE, func=NULL)
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' @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')}.
#' @seealso \code{\link{renderText}} for displaying the value returned from a
#' function, instead of the printed output.
#'
#' @example res/text-example.R
#'
#' @export
renderPrint <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
renderPrint <- function(expr, env = parent.frame(), quoted = FALSE, func = NULL,
width = getOption('width')) {
if (!is.null(func)) {
shinyDeprecated(msg="renderPrint: argument 'func' is deprecated. Please use 'expr' instead.")
} else {
@@ -368,6 +369,8 @@ renderPrint <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
}
markRenderFunction(verbatimTextOutput, function() {
op <- options(width = width)
on.exit(options(op), add = TRUE)
paste(capture.output(func()), collapse = "\n")
})
}

View File

@@ -3,7 +3,8 @@
\alias{renderPrint}
\title{Printable Output}
\usage{
renderPrint(expr, env = parent.frame(), quoted = FALSE, func = NULL)
renderPrint(expr, env = parent.frame(), quoted = FALSE, func = NULL,
width = getOption("width"))
}
\arguments{
\item{expr}{An expression that may print output and/or return a printable R
@@ -14,7 +15,9 @@ object.}
\item{quoted}{Is \code{expr} a quoted expression (with \code{quote()})? This}
\item{func}{A function that may print output and/or return a printable R
object (deprecated; use \code{expr} instead).}
object (deprecated; use \code{expr} instead).}
\item{width}{The value for \code{\link{options}('width')}.}
}
\description{
Makes a reactive version of the given function that captures any printed