Save a D3 visualization to PNG (e.g. for including in another document).
save_d3_png(
d3,
file,
background = "white",
width = 992,
height = 744,
delay = 0.2,
zoom = 1
)
D3 visualization to save
File to save HTML into
Text string giving the html background color of the widget. Defaults to white.
Image width
Image height
Time to wait before taking screenshot, in seconds. Sometimes a longer delay is needed for all assets to display properly.
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).
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()
).