Skip to content

Commit

Permalink
Update documentation for renderXX
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Feb 14, 2013
1 parent e26f175 commit e406a76
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 272 deletions.
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ export(plotOutput)
export(pre)
export(radioButtons)
export(reactive)
export(reactivePlot)
export(reactivePrint)
export(reactiveTable)
export(reactiveText)
export(reactiveTimer)
export(reactiveUI)
export(reactiveValues)
export(reactiveValuesToList)
export(renderPlot)
Expand Down
2 changes: 1 addition & 1 deletion R/bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ tabsetPanel <- function(..., id = NULL) {
#' @param outputId output variable to read the value from
#' @return A text output element that can be included in a panel
#' @details Text is HTML-escaped prior to rendering. This element is often used
#' to dispaly \link{renderText} output variables.
#' to display \link{renderText} output variables.
#' @examples
#' h3(textOutput("caption"))
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/reactives.R
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ Observer <- setRefClass(
#'
#' # In a normal Shiny app, the web client will trigger flush events. If you
#' # are at the console, you can force a flush with flushReact()
#' flushReact()
#' shiny:::flushReact()
#'
#' @export
observe <- function(x, env=parent.frame(), quoted=FALSE, label=NULL,
Expand Down
70 changes: 64 additions & 6 deletions R/shinywrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ suppressPackageStartupMessages({

#' Plot Output
#'
#' Creates a reactive plot that is suitable for assigning to an \code{output}
#' Renders a reactive plot that is suitable for assigning to an \code{output}
#' slot.
#'
#' The corresponding HTML output tag should be \code{div} or \code{img} and have
Expand All @@ -17,7 +17,7 @@ suppressPackageStartupMessages({
#' output. Notably, plain \code{png} output on Linux and Windows may not
#' antialias some point shapes, resulting in poor quality output.
#'
#' @param func A function that generates a plot.
#' @param expr An expression that generates a plot.
#' @param width The width of the rendered plot, in pixels; or \code{'auto'} to
#' use the \code{offsetWidth} of the HTML element that is bound to this plot.
#' You can also pass in a function that returns the width in pixels or
Expand All @@ -30,6 +30,11 @@ suppressPackageStartupMessages({
#' values and functions.
#' @param ... Arguments to be passed through to \code{\link[grDevices]{png}}.
#' These can be used to set the width, height, background color, etc.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#' @param func A function that generates a plot (deprecated; use \code{expr}
#' instead).
#'
#' @export
renderPlot <- function(expr, width='auto', height='auto', ...,
Expand Down Expand Up @@ -110,10 +115,15 @@ renderPlot <- function(expr, width='auto', height='auto', ...,
#' The corresponding HTML output tag should be \code{div} and have the CSS class
#' name \code{shiny-html-output}.
#'
#' @param func A function that returns an R object that can be used with
#' @param expr An expression that returns an R object that can be used with
#' \code{\link[xtable]{xtable}}.
#' @param ... Arguments to be passed through to \code{\link[xtable]{xtable}} and
#' \code{\link[xtable]{print.xtable}}.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? 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).
#'
#' @export
renderTable <- function(expr, ..., env=parent.frame(), quoted=FALSE, func=NULL) {
Expand Down Expand Up @@ -160,8 +170,12 @@ renderTable <- function(expr, ..., env=parent.frame(), quoted=FALSE, func=NULL)
#' returns \code{NULL} then \code{NULL} will actually be visible in the output.
#' To display nothing, make your function return \code{\link{invisible}()}.
#'
#' @param func A function that may print output and/or return a printable R
#' @param expr An expression that may print output and/or return a printable R
#' object.
#' @param env The environment in which to evaluate \code{expr}.
#' @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).
#'
#' @seealso \code{\link{renderText}} for displaying the value returned from a
#' function, instead of the printed output.
Expand Down Expand Up @@ -198,8 +212,13 @@ renderPrint <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
#' The result of executing \code{func} will passed to \code{cat}, inside a
#' \code{\link[utils]{capture.output}} call.
#'
#' @param func A function that returns an R object that can be used as an
#' @param expr An expression that returns an R object that can be used as an
#' argument to \code{cat}.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? 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 as an
#' argument to \code{cat}.(deprecated; use \code{expr} instead).
#'
#' @seealso \code{\link{renderPrint}} for capturing the print output of a
#' function, rather than the returned text value.
Expand Down Expand Up @@ -228,8 +247,13 @@ renderText <- function(expr, env=parent.frame(), quoted=FALSE, func=NULL) {
#' The corresponding HTML output tag should be \code{div} and have the CSS class
#' name \code{shiny-html-output} (or use \code{\link{uiOutput}}).
#'
#' @param func A function that returns a Shiny tag object, \code{\link{HTML}},
#' @param expr An expression that returns a Shiny tag object, \code{\link{HTML}},
#' or a list of such objects.
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' 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).
#'
#' @seealso conditionalPanel
#'
Expand Down Expand Up @@ -307,22 +331,56 @@ downloadHandler <- function(filename, content, contentType=NA) {


# Deprecated functions ------------------------------------------------------

#' Plot output (deprecated)
#'
#' See \code{\link{renderPlot}}.
#' @param func A function.
#' @param width Width.
#' @param height Height.
#' @param ... Other arguments to pass on.
#' @export
reactivePlot <- function(func, width='auto', height='auto', ...) {
shinyDeprecated(new="renderPlot")
renderPlot({ func() }, width='auto', height='auto', ...)
}

#' Table output (deprecated)
#'
#' See \code{\link{renderTable}}.
#' @param func A function.
#' @param ... Other arguments to pass on.
#' @export
reactiveTable <- function(func, ...) {
shinyDeprecated(new="renderTable")
renderTable({ func() })
}

#' Print output (deprecated)
#'
#' See \code{\link{renderPrint}}.
#' @param func A function.
#' @export
reactivePrint <- function(func) {
shinyDeprecated(new="renderPrint")
renderPrint({ func() })
}

#' UI output (deprecated)
#'
#' See \code{\link{renderUI}}.
#' @param func A function.
#' @export
reactiveUI <- function(func) {
shinyDeprecated(new="renderUI")
renderUI({ func() })
}

#' Text output (deprecated)
#'
#' See \code{\link{renderText}}.
#' @param func A function.
#' @export
reactiveText <- function(func) {
shinyDeprecated(new="renderText")
renderText({ func() })
Expand Down
4 changes: 2 additions & 2 deletions man/htmlOutput.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
}
\details{
\code{uiOutput} is intended to be used with
\code{reactiveUI} on the server side. It is currently
just an alias for \code{htmlOutput}.
\code{renderUI} on the server side. It is currently just
an alias for \code{htmlOutput}.
}
\examples{
htmlOutput("summary")
Expand Down
2 changes: 1 addition & 1 deletion man/observe.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ obsD <- observe(expr_q, quoted = TRUE)
# In a normal Shiny app, the web client will trigger flush events. If you
# are at the console, you can force a flush with flushReact()
flushReact()
shiny:::flushReact()
}
2 changes: 1 addition & 1 deletion man/plotOutput.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
A plot output element that can be included in a panel
}
\description{
Render a \link{reactivePlot} within an application page.
Render a \link{renderPlot} within an application page.
}
\examples{
# Show a plot of the generated distribution
Expand Down
38 changes: 6 additions & 32 deletions man/reactivePlot.Rd
Original file line number Diff line number Diff line change
@@ -1,45 +1,19 @@
\name{reactivePlot}
\alias{reactivePlot}
\title{Plot Output}
\title{Plot output (deprecated)}
\usage{
reactivePlot(func, width = "auto", height = "auto", ...)
}
\arguments{
\item{func}{A function that generates a plot.}
\item{func}{A function.}

\item{width}{The width of the rendered plot, in pixels;
or \code{'auto'} to use the \code{offsetWidth} of the
HTML element that is bound to this plot. You can also
pass in a function that returns the width in pixels or
\code{'auto'}; in the body of the function you may
reference reactive values and functions.}
\item{width}{Width.}

\item{height}{The height of the rendered plot, in pixels;
or \code{'auto'} to use the \code{offsetHeight} of the
HTML element that is bound to this plot. You can also
pass in a function that returns the width in pixels or
\code{'auto'}; in the body of the function you may
reference reactive values and functions.}
\item{height}{Height.}

\item{...}{Arguments to be passed through to
\code{\link[grDevices]{png}}. These can be used to set
the width, height, background color, etc.}
\item{...}{Other arguments to pass on.}
}
\description{
Creates a reactive plot that is suitable for assigning to
an \code{output} slot.
}
\details{
The corresponding HTML output tag should be \code{div} or
\code{img} and have the CSS class name
\code{shiny-plot-output}.

For output, it will try to use the following devices, in
this order: quartz (via \code{\link[grDevices]{png}}),
then \code{\link[Cairo]{CairoPNG}}, and finally
\code{\link[grDevices]{png}}. This is in order of quality
of output. Notably, plain \code{png} output on Linux and
Windows may not antialias some point shapes, resulting in
poor quality output.
See \code{\link{renderPlot}}.
}

94 changes: 3 additions & 91 deletions man/reactivePrint.Rd
Original file line number Diff line number Diff line change
@@ -1,101 +1,13 @@
\name{reactivePrint}
\alias{reactivePrint}
\title{Printable Output}
\title{Print output (deprecated)}
\usage{
reactivePrint(func)
}
\arguments{
\item{func}{A function that may print output and/or
return a printable R object.}
\item{func}{A function.}
}
\description{
Makes a reactive version of the given function that
captures any printed output, and also captures its
printable result (unless \code{\link{invisible}}), into a
string. The resulting function is suitable for assigning
to an \code{output} slot.
}
\details{
The corresponding HTML output tag can be anything (though
\code{pre} is recommended if you need a monospace font
and whitespace preserved) and should have the CSS class
name \code{shiny-text-output}.

The result of executing \code{func} will be printed
inside a \code{\link[utils]{capture.output}} call.

Note that unlike most other Shiny output functions, if
the given function returns \code{NULL} then \code{NULL}
will actually be visible in the output. To display
nothing, make your function return
\code{\link{invisible}()}.
}
\examples{
isolate({

# reactivePrint captures any print output, converts it to a string, and
# returns it
visFun <- reactivePrint(function() "foo")
visFun()
# '[1] "foo"'

invisFun <- reactivePrint(function() invisible("foo"))
invisFun()
# ''

multiprintFun <- reactivePrint(function() {
print("foo");
"bar"
})
multiprintFun()
# '[1] "foo"\\n[1] "bar"'

nullFun <- reactivePrint(function() NULL)
nullFun()
# 'NULL'

invisNullFun <- reactivePrint(function() invisible(NULL))
invisNullFun()
# ''

vecFun <- reactivePrint(function() 1:5)
vecFun()
# '[1] 1 2 3 4 5'


# Contrast with reactiveText, which takes the value returned from the function
# and uses cat() to convert it to a string
visFun <- reactiveText(function() "foo")
visFun()
# 'foo'

invisFun <- reactiveText(function() invisible("foo"))
invisFun()
# 'foo'

multiprintFun <- reactiveText(function() {
print("foo");
"bar"
})
multiprintFun()
# 'bar'

nullFun <- reactiveText(function() NULL)
nullFun()
# ''

invisNullFun <- reactiveText(function() invisible(NULL))
invisNullFun()
# ''

vecFun <- reactiveText(function() 1:5)
vecFun()
# '1 2 3 4 5'

})
}
\seealso{
\code{\link{reactiveText}} for displaying the value
returned from a function, instead of the printed output.
See \code{\link{renderPrint}}.
}

16 changes: 4 additions & 12 deletions man/reactiveTable.Rd
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
\name{reactiveTable}
\alias{reactiveTable}
\title{Table Output}
\title{Table output (deprecated)}
\usage{
reactiveTable(func, ...)
}
\arguments{
\item{func}{A function that returns an R object that can
be used with \code{\link[xtable]{xtable}}.}
\item{func}{A function.}

\item{...}{Arguments to be passed through to
\code{\link[xtable]{xtable}} and
\code{\link[xtable]{print.xtable}}.}
\item{...}{Other arguments to pass on.}
}
\description{
Creates a reactive table that is suitable for assigning
to an \code{output} slot.
}
\details{
The corresponding HTML output tag should be \code{div}
and have the CSS class name \code{shiny-html-output}.
See \code{\link{renderTable}}.
}

Loading

0 comments on commit e406a76

Please sign in to comment.