fig <- px_scatter(
px_data_iris(),
x = ~sepal_width, y = ~sepal_length, color = ~species
)
png_file <- tempfile(fileext = ".png")
save_image(fig, png_file, width = 700, height = 450, scale = 2)save_image() exports a figure with plotly.js’s own image export, running in a headless Chromium-based browser driven by chromote. No Python, Kaleido or orca is involved.
Formats and options
| Extension | Notes |
|---|---|
.png, .jpeg/.jpg, .webp
|
scale multiplies the resolution (scale = 2 for high-DPI) |
.svg |
WebGL traces (scattergl, 3D, maps) are embedded as images |
.pdf |
the SVG printed to a page the figure’s size |
.eps |
converted from the SVG; needs the rsvg package |
-
width,height: pixels; default to the figure’s layout size, else 700 × 500. - LaTeX (
TeX()) is typeset with the MathJax bundled with plotly.core, so it works offline. - The browser starts on the first export (about a second) and is reused for the rest of the session.
chrome_exporter()gives a browser of your own, with$transform(p, file, ...)and$shutdown().
Setup
Requirements: chromote ≥ 0.5.0 (install.packages("chromote")), rsvg for EPS only, and a Chromium-based browser. The browser is not an R package, but on most machines it needs no separate install: save_image() uses the first of
- the browser in the
CHROMOTE_CHROMEenvironment variable; - an installed Google Chrome;
- an installed Microsoft Edge (on every Windows 10/11 machine), Chromium or Brave, including per-user installs;
- a Chrome Headless Shell downloaded earlier.
If there is none, it can download Chrome Headless Shell (about 125 MB) from within R, into the user cache, without administrator rights. On Linux it also downloads any shared libraries the browser lacks: the packages providing them come from the system’s own repositories (apt-get download, dnf download; Debian/Ubuntu and RHEL-family systems) and are unpacked into tools::R_user_dir("plotly.core", "cache"), not installed system-wide.
| Session | What happens |
|---|---|
| Interactive | One yes/no question, then install_chrome() runs and the export continues |
| Script, scheduled job, CI | No download; an error says to run plotly.core::install_chrome() once (e.g. in a setup script or Dockerfile) |
| R Markdown / Quarto | Never downloads; without a browser, figures are included as widgets |
remove_chrome() deletes plotly.core’s downloads; remove_chrome(browser = TRUE) also removes chromote’s Chrome Headless Shell.
Linux servers
With administrator rights, the libraries can instead be installed system-wide (the error message shows the command for the system):
# Debian, Ubuntu
sudo apt-get install -y libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
libgbm1 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libpango-1.0-0 \
libcairo2 libasound2
# RHEL, Rocky, AlmaLinux, Fedora, Amazon Linux
sudo dnf install -y nss nspr atk at-spi2-atk cups-libs libdrm mesa-libgbm libxkbcommon \
libXcomposite libXdamage libXfixes libXrandr pango cairo alsa-lib- Running as root (common in containers): Chrome needs
--no-sandbox, which chromote adds itself in Docker and CI; elsewhere usechromote::set_chrome_args(c(chromote::get_chrome_args(), "--no-sandbox")). Small/dev/shm: add"--disable-dev-shm-usage"the same way. - Text is drawn with the fonts Chrome finds; minimal images may need fonts installed to match desktop output.
Where set-up from R isn’t enough
| Situation | What to do |
|---|---|
| No internet, proxy, or blocked downloads (storage.googleapis.com) | Set R’s proxy (https_proxy), or copy a browser in and set CHROMOTE_CHROME
|
| Linux on ARM64 (no Chrome Headless Shell build) | Install the distribution’s Chromium package |
| Old OS (e.g. CentOS/RHEL 7, Windows before 10) | Current Chrome can’t run there; use a newer system |
| Linux without package lists (slim images), SUSE, Arch | Install the libraries, or Chromium, with the package manager |
| Alpine |
apk add chromium, CHROMOTE_CHROME=/usr/bin/chromium-browser
|
Locked-down machines (AppLocker/WDAC, MDM, antivirus), noexec home |
Use an approved installed Chrome or Edge |
| webR / Shinylive | Not possible: R can’t start other programs there |
| Hosted R (Posit Connect, shinyapps.io) | Install a browser in the image, or run install_chrome() at deployment |
Performance compared with Kaleido
Kaleido (the plotly R package’s save_image()) also drives Chrome, and can keep it running between exports. The difference is the data path: the figure goes from R to JSON text, is parsed into Python objects by reticulate, then serialized again by Kaleido and sent to Chrome as JSON numbers. plotly.core sends it straight from R to Chrome, with numeric arrays as base64 typed arrays, which are smaller and much quicker to write and to read.
| Figure (700 × 500 PNG) | Kaleido 1.5 (s) | plotly.core (s) | Faster |
|---|---|---|---|
| Scatter, 150 points | 0.065 | 0.024 | 2.7× |
| Line, 100,000 points | 1.508 | 0.138 | 10.9× |
| Line, 1,000,000 points | 13.033 | 0.767 | 17.0× |
| Heatmap, 500 × 500 | 0.565 | 0.168 | 3.4× |
| Heatmap, 1000 × 1000 | 2.002 | 0.557 | 3.6× |
Seconds per export, median of 5, with both browsers already running (kaleido.start_sync_server() for Kaleido), the same plotly.js 4.3.0 and Chrome 157, and matching images. Kaleido’s time includes writing the figure’s JSON in R (0.86 s at 1M points; plotly.core’s typed-array JSON takes 0.13 s) and parsing it in Python (0.16 s). Apple M3 Pro, macOS 26.5.1, 2026-11-16. Starting either browser adds about 1.3 s to the first export.
Set-up compared:
| orca | Kaleido | plotly.core | |
|---|---|---|---|
| Install | separate command-line app (npm/installer) | Python + kaleido, plotly via reticulate |
install.packages("chromote") |
| Browser | bundled (Electron) | Chrome, installed separately (Kaleido 1.x) | installed Chrome/Edge/Chromium/Brave, or downloaded from R |
Troubleshooting
| Message | Fix |
|---|---|
| needs chromote 0.5.0 or later | install.packages("chromote") |
| needs Chrome, which wasn’t found |
plotly.core::install_chrome(), or set CHROMOTE_CHROME
|
| shared libraries it needs are missing |
plotly.core::install_chrome(), or the sudo command shown |
| Chrome … failed to start | Read Chrome’s output in the message; see Linux servers |
| EPS export needs the rsvg package | install.packages("rsvg") |