save_d3_png: Save a D3 visualization as a PNG image

View source: R/publish.R

save_d3_pngR Documentation

Save a D3 visualization as a PNG image

Description

Save a D3 visualization to PNG (e.g. for including in another document).

Usage

save_d3_png(
  d3,
  file,
  background = "white",
  width = 992,
  height = 744,
  delay = 0.2,
  zoom = 1
)

Arguments

d3

D3 visualization to save

file

File to save HTML into

background

Text string giving the html background color of the widget. Defaults to white.

width

Image width

height

Image height

delay

Time to wait before taking screenshot, in seconds. Sometimes a longer delay is needed for all assets to display properly.

zoom

A number specifying the zoom factor. A zoom factor of 2 will result in twice as many pixels vertically and horizontally. Note that using 2 is not exactly the same as taking a screenshot on a HiDPI (Retina) device: it is like increasing the zoom to 200 doubling the height and width of the browser window. This differs from using a HiDPI device because some web pages load different, higher-resolution images when they know they will be displayed on a HiDPI device (but using zoom will not report that there is a HiDPI device).

Details

PNG versions of D3 visualizations are created by displaying them in an offscreen web browser and taking a screenshot of the rendered web page.

Using the save_d3_png() function requires that you install the webshot package, as well as the phantom.js headless browser (which you can install using the function webshot::install_phantomjs()).

See Also

save_d3_html()


r2d3 documentation built on March 18, 2022, 7:17 p.m.