Skip to contents

Exports a widget created by draw() (or any of the draw_* functions) to a static file. Supports .svg for ECharts, Sigma networks, and MapLibre maps via Node.js server-side rendering, including complete draw_panels() figures. Requires a node binary on PATH.

Usage

save_drawing(widget, filename, width = NULL, height = NULL)

Arguments

widget

htmlwidget: A widget returned by draw() or a draw_* function.

filename

Character scalar: Nonempty output path with an extension.

width

Optional Numeric scalar (0, Inf): Finite image width in pixels. Unset uses the widget's numeric width, or 800 for a relative/unspecified width.

height

Optional Numeric scalar (0, Inf): Finite image height in pixels. Unset uses the widget's numeric height, or 600 for a relative/unspecified height.

Value

The filename, invisibly.

Details

Callbacks under tooltips, axis pointers, and interactive toolbox controls are omitted. Other JavaScript callbacks are rejected because discarding them could change visible content. Built-in Gantt, dendrogram, and boxplot point renderers are shared with the browser widget and use JSON parameters. Networks share their deterministic layout and styles with the interactive widget. Maps share geometry, location joins, and color scales and use a Mercator projection. Exports show the initial configured view; browser camera changes and hover states are not stored in the R widget. SVG text remains editable. Network labels are fitted to the page and suppressed when they overlap.

Examples

# SVG export shells out to Node.js, so run it only where node exists.
if (nzchar(Sys.which("node"))) {
  chart <- draw_bar(x = c("A", "B", "C"), y = c(3, 7, 2))
  path <- file.path(tempdir(), "chart.svg")
  save_drawing(chart, path)
  unlink(path)
}