Capture a plot as a PNG file. — plotPNG

v1.10.0|Source: R/imageutils.R

Description

The PNG graphics device used is determined in the following order:

  • If the ragg package is installed (and the shiny.useragg is not set to FALSE), then use ragg::agg_png().

  • If a quartz device is available (i.e., capabilities("aqua") is TRUE), then use png(type = "quartz").

  • If the Cairo package is installed (and the shiny.usecairo option is not set to FALSE), then use Cairo::CairoPNG().

  • Otherwise, use grDevices::png(). In this case, Linux and Windows may not antialias some point shapes, resulting in poor quality output.

plotPNG(
  func,
  filename = tempfile(fileext = ".png"),
  width = 400,
  height = 400,
  res = 72,
  ...
)

Arguments

func

A function that generates a plot.

filename

The name of the output file. Defaults to a temp file with extension .png.

width

Width in pixels.

height

Height in pixels.

res

Resolution in pixels per inch. This value is passed to the graphics device. Note that this affects the resolution of PNG rendering in R; it won't change the actual ppi of the browser.

...

Arguments to be passed through to the graphics device. These can be used to set the width, height, background color, etc.

Value

A path to the newly generated PNG file.

Details

A NULL value provided to width or height is ignored (i.e., the default width or height of the graphics device is used).