EVOLUTION-MANAGER
Edit File: renderImage.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Image file output</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for renderImage {shiny}"><tr><td>renderImage {shiny}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Image file output</h2> <h3>Description</h3> <p>Renders a reactive image that is suitable for assigning to an <code>output</code> slot. </p> <h3>Usage</h3> <pre> renderImage( expr, env = parent.frame(), quoted = FALSE, deleteFile, outputArgs = list() ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>expr</code></td> <td> <p>An expression that returns a list.</p> </td></tr> <tr valign="top"><td><code>env</code></td> <td> <p>The environment in which to evaluate <code>expr</code>.</p> </td></tr> <tr valign="top"><td><code>quoted</code></td> <td> <p>Is <code>expr</code> a quoted expression (with <code>quote()</code>)? This is useful if you want to save an expression in a variable.</p> </td></tr> <tr valign="top"><td><code>deleteFile</code></td> <td> <p>Should the file in <code>func()$src</code> be deleted after it is sent to the client browser? Generally speaking, if the image is a temp file generated within <code>func</code>, then this should be <code>TRUE</code>; if the image is not a temp file, this should be <code>FALSE</code>. (For backward compatibility reasons, if this argument is missing, a warning will be emitted, and if the file is in the temp directory it will be deleted. In the future, this warning will become an error.)</p> </td></tr> <tr valign="top"><td><code>outputArgs</code></td> <td> <p>A list of arguments to be passed through to the implicit call to <code><a href="plotOutput.html">imageOutput()</a></code> when <code>renderImage</code> is used in an interactive R Markdown document.</p> </td></tr> </table> <h3>Details</h3> <p>The expression <code>expr</code> must return a list containing the attributes for the <code>img</code> object on the client web page. For the image to display, properly, the list must have at least one entry, <code>src</code>, which is the path to the image file. It may also useful to have a <code>contentType</code> entry specifying the MIME type of the image. If one is not provided, <code>renderImage</code> will try to autodetect the type, based on the file extension. </p> <p>Other elements such as <code>width</code>, <code>height</code>, <code>class</code>, and <code>alt</code>, can also be added to the list, and they will be used as attributes in the <code>img</code> object. </p> <p>The corresponding HTML output tag should be <code>div</code> or <code>img</code> and have the CSS class name <code>shiny-image-output</code>. </p> <h3>See Also</h3> <p>For more details on how the images are generated, and how to control the output, see <code><a href="plotPNG.html">plotPNG()</a></code>. </p> <h3>Examples</h3> <pre> ## Only run examples in interactive R sessions if (interactive()) { options(device.ask.default = FALSE) ui <- fluidPage( sliderInput("n", "Number of observations", 2, 1000, 500), plotOutput("plot1"), plotOutput("plot2"), plotOutput("plot3") ) server <- function(input, output, session) { # A plot of fixed size output$plot1 <- renderImage({ # A temp file to save the output. It will be deleted after renderImage # sends it, because deleteFile=TRUE. outfile <- tempfile(fileext='.png') # Generate a png png(outfile, width=400, height=400) hist(rnorm(input$n)) dev.off() # Return a list list(src = outfile, alt = "This is alternate text") }, deleteFile = TRUE) # A dynamically-sized plot output$plot2 <- renderImage({ # Read plot2's width and height. These are reactive values, so this # expression will re-run whenever these values change. width <- session$clientData$output_plot2_width height <- session$clientData$output_plot2_height # A temp file to save the output. outfile <- tempfile(fileext='.png') png(outfile, width=width, height=height) hist(rnorm(input$n)) dev.off() # Return a list containing the filename list(src = outfile, width = width, height = height, alt = "This is alternate text") }, deleteFile = TRUE) # Send a pre-rendered image, and don't delete the image after sending it # NOTE: For this example to work, it would require files in a subdirectory # named images/ output$plot3 <- renderImage({ # When input$n is 1, filename is ./images/image1.jpeg filename <- normalizePath(file.path('./images', paste('image', input$n, '.jpeg', sep=''))) # Return a list containing the filename list(src = filename) }, deleteFile = FALSE) } shinyApp(ui, server) } </pre> <hr /><div style="text-align: center;">[Package <em>shiny</em> version 1.5.0 <a href="00Index.html">Index</a>]</div> </body></html>