Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

renderPlot

Plot Output


Description

Renders a reactive plot that is suitable for assigning to an output slot.

Usage

renderPlot(
  expr,
  width = "auto",
  height = "auto",
  res = 72,
  ...,
  alt = "Plot object",
  env = parent.frame(),
  quoted = FALSE,
  execOnResize = FALSE,
  outputArgs = list()
)

Arguments

expr

An expression that generates a plot.

width, height

Height and width can be specified in three ways:

  • "auto", the default, uses the size specified by plotOutput() (i.e. the offsetWidth/'offsetHeight“ of the HTML element bound to this plot.)

  • An integer, defining the width/height in pixels.

  • A function that returns the width/height in pixels (or "auto"). The function is executed in a reactive context so that you can refer to reactive values and expression to make the width/height reactive.

When rendering an inline plot, you must provide numeric values (in pixels) to both width and height.

res

Resolution of resulting plot, in pixels per inch. This value is passed to grDevices::png(). Note that this affects the resolution of PNG rendering in R; it won't change the actual ppi of the browser.

...

Arguments to be passed through to grDevices::png(). These can be used to set the width, height, background color, etc.

alt

Alternate text for the HTML <img> tag if it cannot be displayed or viewed (i.e., the user uses a screen reader). In addition to a character string, the value may be a reactive expression (or a function referencing reactive values) that returns a character string. NULL or "" is not recommended because those should be limited to decorative images (the default is "Plot object").

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.

execOnResize

If FALSE (the default), then when a plot is resized, Shiny will replay the plot drawing commands with grDevices::replayPlot() instead of re-executing expr. This can result in faster plot redrawing, but there may be rare cases where it is undesirable. If you encounter problems when resizing a plot, you can have Shiny re-execute the code on resize by setting this to TRUE.

outputArgs

A list of arguments to be passed through to the implicit call to plotOutput() when renderPlot is used in an interactive R Markdown document.

Details

The corresponding HTML output tag should be div or img and have the CSS class name shiny-plot-output.

Interactive plots

With ggplot2 graphics, the code in renderPlot should return a ggplot object; if instead the code prints the ggplot2 object with something like print(p), then the coordinates for interactive graphics will not be properly scaled to the data space.

See plotOutput() for more information about interactive plots.

See Also

For the corresponding client-side output function, and example usage, see plotOutput(). For more details on how the plots are generated, and how to control the output, see plotPNG(). renderCachedPlot() offers a way to cache generated plots to expedite the rendering of identical plots.


shiny

Web Application Framework for R

v1.6.0
GPL-3 | file LICENSE
Authors
Winston Chang [aut, cre], Joe Cheng [aut], JJ Allaire [aut], Carson Sievert [aut], Barret Schloerke [aut], Yihui Xie [aut], Jeff Allen [aut], Jonathan McPherson [aut], Alan Dipert [aut], Barbara Borges [aut], RStudio [cph], jQuery Foundation [cph] (jQuery library and jQuery UI library), jQuery contributors [ctb, cph] (jQuery library; authors listed in inst/www/shared/jquery-AUTHORS.txt), jQuery UI contributors [ctb, cph] (jQuery UI library; authors listed in inst/www/shared/jqueryui/AUTHORS.txt), Mark Otto [ctb] (Bootstrap library), Jacob Thornton [ctb] (Bootstrap library), Bootstrap contributors [ctb] (Bootstrap library), Twitter, Inc [cph] (Bootstrap library), Prem Nawaz Khan [ctb] (Bootstrap accessibility plugin), Victor Tsaran [ctb] (Bootstrap accessibility plugin), Dennis Lembree [ctb] (Bootstrap accessibility plugin), Srinivasu Chakravarthula [ctb] (Bootstrap accessibility plugin), Cathy O'Connor [ctb] (Bootstrap accessibility plugin), PayPal, Inc [cph] (Bootstrap accessibility plugin), Stefan Petre [ctb, cph] (Bootstrap-datepicker library), Andrew Rowls [ctb, cph] (Bootstrap-datepicker library), Dave Gandy [ctb, cph] (Font-Awesome font), Brian Reavis [ctb, cph] (selectize.js library), Salmen Bejaoui [ctb, cph] (selectize-plugin-a11y library), Denis Ineshin [ctb, cph] (ion.rangeSlider library), Sami Samhuri [ctb, cph] (Javascript strftime library), SpryMedia Limited [ctb, cph] (DataTables library), John Fraser [ctb, cph] (showdown.js library), John Gruber [ctb, cph] (showdown.js library), Ivan Sagalaev [ctb, cph] (highlight.js library), R Core Team [ctb, cph] (tar implementation from R)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.