Skip to contents

Shows a card that stats_card() or another card function drew: in the Viewer pane of RStudio or Positron, as a web page, or in the Plots pane, as a picture.

Usage

view_card(card, where = c("viewer", "plots"))

Arguments

card

A card: the file that a card function drew, an .svg or a .png, as the function returns it, or the SVG code that it returns with file = NULL.

where

"viewer", the Viewer pane, or "plots", the Plots pane.

Value

card, invisibly.

Details

The Viewer shows the card as a web page: an SVG card stays sharp at any size and tells the value of each column and bar when you point at it, and a card wider than the pane shrinks to fit it. The Viewer is the one that the viewer option names, which RStudio, Positron and the R extension of VS Code set; without it, as in R on its own, the card opens in your web browser.

The Plots pane shows the card as a picture, as a GitHub profile does, as large as the pane allows, and draws it again when the pane is resized. Outside RStudio and Positron, the picture goes to the current graphics device, such as a window, a file that grDevices::png() opens, or a figure of an R Markdown or Quarto document. There, a PNG card needs the png package.

Examples

card <- stats_card(example_stats(), file = NULL)
view_card(card, "plots")

if (interactive()) view_card(card)

# the file that a card function drew, as it returns it
file <- code_card(example_stats(), tempfile(fileext = ".svg"), theme = "light")
if (interactive()) view_card(file)