A light wrapper for shiny::plotOutput() that uses gridlayout-friendly sizing defaults.

grid_card_plot(area, outputId = area, ...)

Arguments

area

Name of grid area, should match an area defined in the layout section of the wrapping grid_page() or grid_container().

outputId

Output id of the plot output. Used to link to server code generating plot. If left unset this will use the same value as the area argument.

...

Arguments passed on to shiny::plotOutput

width,height

Image width/height. Must be a valid CSS unit (like "100%", "400px", "auto") or a number, which will be coerced to a string and have "px" appended. These two arguments are ignored when inline = TRUE, in which case the width/height of a plot must be specified in renderPlot(). Note that, for height, using "auto" or "100%" generally will not work as expected, because of how height is computed with HTML/CSS.

click

This can be NULL (the default), a string, or an object created by the clickOpts() function. If you use a value like "plot_click" (or equivalently, clickOpts(id="plot_click")), the plot will send coordinates to the server whenever it is clicked, and the value will be accessible via input$plot_click. The value will be a named list with x and y elements indicating the mouse position.

dblclick

This is just like the click argument, but for double-click events.

hover

Similar to the click argument, this can be NULL (the default), a string, or an object created by the hoverOpts() function. If you use a value like "plot_hover" (or equivalently, hoverOpts(id="plot_hover")), the plot will send coordinates to the server pauses on the plot, and the value will be accessible via input$plot_hover. The value will be a named list with x and y elements indicating the mouse position. To control the hover time or hover delay type, you must use hoverOpts().

brush

Similar to the click argument, this can be NULL (the default), a string, or an object created by the brushOpts() function. If you use a value like "plot_brush" (or equivalently, brushOpts(id="plot_brush")), 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 input$plot_brush. 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 xmin, xmax, ymin, and ymax elements indicating the brush area. To control the brush behavior, use brushOpts(). Multiple imageOutput/plotOutput calls may share the same id value; brushing one image or plot will cause any other brushes with the same id to disappear.

inline

use an inline (span()) or block container (div()) for the output

fill

Whether or not the returned tag should be treated as a fill item, meaning that its height is allowed to grow/shrink to fit a fill container with an opinionated height (see htmltools::bindFillRole()) with an opinionated height. Examples of fill containers include bslib::card() and bslib::card_body_fill().

Value

A grid panel filled with plot output

Examples

if (FALSE) {
library(gridlayout)
library(shiny)
library(bslib)

shinyApp(
  ui = grid_page(
    layout = c(
      "header  header",
      "sidebar distPlot"
    ),
    row_sizes = c("50px", "1fr"),
    col_sizes = c("200px", "1fr"),
    grid_card_text("header", "This is my header"),
    grid_card(
      area = "sidebar",
      card_header("Settings"),
      card_body(
        sliderInput("bins", "Number of bins:", 1, 50, 30, width = "100%")
      )
    ),
    grid_card_plot("distPlot")
  ),
  server = function(input, output) {
    output$distPlot <- renderPlot({
      x    <- faithful[, 2]
      bins <- seq(min(x), max(x), length.out = input$bins + 1)
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
  }
)
}