Debian Codegraph @

man/renderPlot.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/render-plot.R
3 \name{renderPlot}
4 \alias{renderPlot}
5 \title{Plot Output}
6 \usage{
7 renderPlot(
8 expr,
9 width = "auto",
10 height = "auto",
11 res = 72,
12 ...,
13 alt = NA,
14 env = parent.frame(),
15 quoted = FALSE,
16 execOnResize = FALSE,
17 outputArgs = list()
18 )
19 }
20 \arguments{
21 \item{expr}{An expression that generates a plot.}
22
23 \item{width, height}{Height and width can be specified in three ways:
24 \itemize{
25 \item \code{"auto"}, the default, uses the size specified by \code{\link[=plotOutput]{plotOutput()}}
26 (i.e. the \code{offsetWidth}/`offsetHeight`` of the HTML element bound to
27 this plot.)
28 \item An integer, defining the width/height in pixels.
29 \item A function that returns the width/height in pixels (or \code{"auto"}).
30 The function is executed in a reactive context so that you can refer to
31 reactive values and expression to make the width/height reactive.
32 }
33
34 When rendering an inline plot, you must provide numeric values (in pixels)
35 to both \code{width} and \code{height}.}
36
37 \item{res}{Resolution of resulting plot, in pixels per inch. This value is
38 passed to \code{\link[=plotPNG]{plotPNG()}}. Note that this affects the resolution of PNG
39 rendering in R; it won't change the actual ppi of the browser.}
40
41 \item{...}{Arguments to be passed through to \code{\link[=plotPNG]{plotPNG()}}.
42 These can be used to set the width, height, background color, etc.}
43
44 \item{alt}{Alternate text for the HTML \verb{<img>} tag if it cannot be displayed
45 or viewed (i.e., the user uses a screen reader). In addition to a character
46 string, the value may be a reactive expression (or a function referencing
47 reactive values) that returns a character string. If the value is \code{NA} (the
48 default), then \code{ggplot2::get_alt_text()} is used to extract alt text from
49 ggplot objects; for other plots, \code{NA} results in alt text of "Plot object".
50 \code{NULL} or \code{""} is not recommended because those should be limited to
51 decorative images.}
52
53 \item{env}{The parent environment for the reactive expression. By default,
54 this is the calling environment, the same as when defining an ordinary
55 non-reactive expression. If \code{expr} is a quosure and \code{quoted} is \code{TRUE},
56 then \code{env} is ignored.}
57
58 \item{quoted}{If it is \code{TRUE}, then the \code{\link[=quote]{quote()}}ed value of \code{expr}
59 will be used when \code{expr} is evaluated. If \code{expr} is a quosure and you
60 would like to use its expression as a value for \code{expr}, then you must set
61 \code{quoted} to \code{TRUE}.}
62
63 \item{execOnResize}{If \code{FALSE} (the default), then when a plot is
64 resized, Shiny will \emph{replay} the plot drawing commands with
65 \code{\link[grDevices:recordplot]{grDevices::replayPlot()}} instead of re-executing \code{expr}.
66 This can result in faster plot redrawing, but there may be rare cases where
67 it is undesirable. If you encounter problems when resizing a plot, you can
68 have Shiny re-execute the code on resize by setting this to \code{TRUE}.}
69
70 \item{outputArgs}{A list of arguments to be passed through to the implicit
71 call to \code{\link[=plotOutput]{plotOutput()}} when \code{renderPlot} is used in an
72 interactive R Markdown document.}
73 }
74 \description{
75 Renders a reactive plot that is suitable for assigning to an \code{output}
76 slot.
77 }
78 \details{
79 The corresponding HTML output tag should be \code{div} or \code{img} and have
80 the CSS class name \code{shiny-plot-output}.
81 }
82 \section{Interactive plots}{
83
84
85 With ggplot2 graphics, the code in \code{renderPlot} should return a ggplot
86 object; if instead the code prints the ggplot2 object with something like
87 \code{print(p)}, then the coordinates for interactive graphics will not be
88 properly scaled to the data space.
89
90 See \code{\link[=plotOutput]{plotOutput()}} for more information about interactive plots.
91 }
92
93 \seealso{
94 For the corresponding client-side output function, and example
95 usage, see \code{\link[=plotOutput]{plotOutput()}}. For more details on how the plots are
96 generated, and how to control the output, see \code{\link[=plotPNG]{plotPNG()}}.
97 \code{\link[=renderCachedPlot]{renderCachedPlot()}} offers a way to cache generated plots to
98 expedite the rendering of identical plots.
99 }