EVOLUTION-MANAGER
Edit File: plotOutput.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: Create an plot or image output element</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 plotOutput {shiny}"><tr><td>plotOutput {shiny}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Create an plot or image output element</h2> <h3>Description</h3> <p>Render a <code><a href="renderPlot.html">renderPlot()</a></code> or <code><a href="renderImage.html">renderImage()</a></code> within an application page. </p> <h3>Usage</h3> <pre> imageOutput( outputId, width = "100%", height = "400px", click = NULL, dblclick = NULL, hover = NULL, brush = NULL, inline = FALSE ) plotOutput( outputId, width = "100%", height = "400px", click = NULL, dblclick = NULL, hover = NULL, brush = NULL, inline = FALSE ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>outputId</code></td> <td> <p>output variable to read the plot/image from.</p> </td></tr> <tr valign="top"><td><code>width, height</code></td> <td> <p>Image width/height. Must be a valid CSS unit (like <code>"100%"</code>, <code>"400px"</code>, <code>"auto"</code>) or a number, which will be coerced to a string and have <code>"px"</code> appended. These two arguments are ignored when <code>inline = TRUE</code>, in which case the width/height of a plot must be specified in <code>renderPlot()</code>. Note that, for height, using <code>"auto"</code> or <code>"100%"</code> generally will not work as expected, because of how height is computed with HTML/CSS.</p> </td></tr> <tr valign="top"><td><code>click</code></td> <td> <p>This can be <code>NULL</code> (the default), a string, or an object created by the <code><a href="clickOpts.html">clickOpts()</a></code> function. If you use a value like <code>"plot_click"</code> (or equivalently, <code>clickOpts(id="plot_click")</code>), the plot will send coordinates to the server whenever it is clicked, and the value will be accessible via <code>input$plot_click</code>. The value will be a named list with <code>x</code> and <code>y</code> elements indicating the mouse position.</p> </td></tr> <tr valign="top"><td><code>dblclick</code></td> <td> <p>This is just like the <code>click</code> argument, but for double-click events.</p> </td></tr> <tr valign="top"><td><code>hover</code></td> <td> <p>Similar to the <code>click</code> argument, this can be <code>NULL</code> (the default), a string, or an object created by the <code><a href="hoverOpts.html">hoverOpts()</a></code> function. If you use a value like <code>"plot_hover"</code> (or equivalently, <code>hoverOpts(id="plot_hover")</code>), the plot will send coordinates to the server pauses on the plot, and the value will be accessible via <code>input$plot_hover</code>. The value will be a named list with <code>x</code> and <code>y</code> elements indicating the mouse position. To control the hover time or hover delay type, you must use <code><a href="hoverOpts.html">hoverOpts()</a></code>.</p> </td></tr> <tr valign="top"><td><code>brush</code></td> <td> <p>Similar to the <code>click</code> argument, this can be <code>NULL</code> (the default), a string, or an object created by the <code><a href="brushOpts.html">brushOpts()</a></code> function. If you use a value like <code>"plot_brush"</code> (or equivalently, <code>brushOpts(id="plot_brush")</code>), the plot will allow the user to "brush" in the plotting area, and will send information about the brushed area to the server, and the value will be accessible via <code>input$plot_brush</code>. Brushing means that the user will be able to draw a rectangle in the plotting area and drag it around. The value will be a named list with <code>xmin</code>, <code>xmax</code>, <code>ymin</code>, and <code>ymax</code> elements indicating the brush area. To control the brush behavior, use <code><a href="brushOpts.html">brushOpts()</a></code>. Multiple <code>imageOutput</code>/<code>plotOutput</code> calls may share the same <code>id</code> value; brushing one image or plot will cause any other brushes with the same <code>id</code> to disappear.</p> </td></tr> <tr valign="top"><td><code>inline</code></td> <td> <p>use an inline (<code>span()</code>) or block container (<code>div()</code>) for the output</p> </td></tr> </table> <h3>Value</h3> <p>A plot or image output element that can be included in a panel. </p> <h3>Interactive plots</h3> <p>Plots and images in Shiny support mouse-based interaction, via clicking, double-clicking, hovering, and brushing. When these interaction events occur, the mouse coordinates will be sent to the server as <code style="white-space: pre;">input$</code> variables, as specified by <code>click</code>, <code>dblclick</code>, <code>hover</code>, or <code>brush</code>. </p> <p>For <code>plotOutput</code>, the coordinates will be sent scaled to the data space, if possible. (At the moment, plots generated by base graphics and ggplot2 support this scaling, although plots generated by lattice and others do not.) If scaling is not possible, the raw pixel coordinates will be sent. For <code>imageOutput</code>, the coordinates will be sent in raw pixel coordinates. </p> <p>With ggplot2 graphics, the code in <code>renderPlot</code> should return a ggplot object; if instead the code prints the ggplot2 object with something like <code>print(p)</code>, then the coordinates for interactive graphics will not be properly scaled to the data space. </p> <h3>Note</h3> <p>The arguments <code>clickId</code> and <code>hoverId</code> only work for R base graphics (see the <span class="pkg"><a href="../../graphics/html/graphics-package.html">graphics</a></span> package). They do not work for <span class="pkg"><a href="../../grid/html/grid-package.html">grid</a></span>-based graphics, such as <span class="pkg">ggplot2</span>, <span class="pkg">lattice</span>, and so on. </p> <h3>See Also</h3> <p>For the corresponding server-side functions, see <code><a href="renderPlot.html">renderPlot()</a></code> and <code><a href="renderImage.html">renderImage()</a></code>. </p> <h3>Examples</h3> <pre> # Only run these examples in interactive R sessions if (interactive()) { # A basic shiny app with a plotOutput shinyApp( ui = fluidPage( sidebarLayout( sidebarPanel( actionButton("newplot", "New plot") ), mainPanel( plotOutput("plot") ) ) ), server = function(input, output) { output$plot <- renderPlot({ input$newplot # Add a little noise to the cars data cars2 <- cars + rnorm(nrow(cars)) plot(cars2) }) } ) # A demonstration of clicking, hovering, and brushing shinyApp( ui = basicPage( fluidRow( column(width = 4, plotOutput("plot", height=300, click = "plot_click", # Equiv, to click=clickOpts(id="plot_click") hover = hoverOpts(id = "plot_hover", delayType = "throttle"), brush = brushOpts(id = "plot_brush") ), h4("Clicked points"), tableOutput("plot_clickedpoints"), h4("Brushed points"), tableOutput("plot_brushedpoints") ), column(width = 4, verbatimTextOutput("plot_clickinfo"), verbatimTextOutput("plot_hoverinfo") ), column(width = 4, wellPanel(actionButton("newplot", "New plot")), verbatimTextOutput("plot_brushinfo") ) ) ), server = function(input, output, session) { data <- reactive({ input$newplot # Add a little noise to the cars data so the points move cars + rnorm(nrow(cars)) }) output$plot <- renderPlot({ d <- data() plot(d$speed, d$dist) }) output$plot_clickinfo <- renderPrint({ cat("Click:\n") str(input$plot_click) }) output$plot_hoverinfo <- renderPrint({ cat("Hover (throttled):\n") str(input$plot_hover) }) output$plot_brushinfo <- renderPrint({ cat("Brush (debounced):\n") str(input$plot_brush) }) output$plot_clickedpoints <- renderTable({ # For base graphics, we need to specify columns, though for ggplot2, # it's usually not necessary. res <- nearPoints(data(), input$plot_click, "speed", "dist") if (nrow(res) == 0) return() res }) output$plot_brushedpoints <- renderTable({ res <- brushedPoints(data(), input$plot_brush, "speed", "dist") if (nrow(res) == 0) return() res }) } ) # Demo of clicking, hovering, brushing with imageOutput # Note that coordinates are in pixels shinyApp( ui = basicPage( fluidRow( column(width = 4, imageOutput("image", height=300, click = "image_click", hover = hoverOpts( id = "image_hover", delay = 500, delayType = "throttle" ), brush = brushOpts(id = "image_brush") ) ), column(width = 4, verbatimTextOutput("image_clickinfo"), verbatimTextOutput("image_hoverinfo") ), column(width = 4, wellPanel(actionButton("newimage", "New image")), verbatimTextOutput("image_brushinfo") ) ) ), server = function(input, output, session) { output$image <- renderImage({ input$newimage # Get width and height of image output width <- session$clientData$output_image_width height <- session$clientData$output_image_height # Write to a temporary PNG file outfile <- tempfile(fileext = ".png") png(outfile, width=width, height=height) plot(rnorm(200), rnorm(200)) dev.off() # Return a list containing information about the image list( src = outfile, contentType = "image/png", width = width, height = height, alt = "This is alternate text" ) }) output$image_clickinfo <- renderPrint({ cat("Click:\n") str(input$image_click) }) output$image_hoverinfo <- renderPrint({ cat("Hover (throttled):\n") str(input$image_hover) }) output$image_brushinfo <- renderPrint({ cat("Brush (debounced):\n") str(input$image_brush) }) } ) } </pre> <hr /><div style="text-align: center;">[Package <em>shiny</em> version 1.5.0 <a href="00Index.html">Index</a>]</div> </body></html>