Export Plotly plots to static images using plotly_static
mainThe plotly_static crate provides an interface to convert Plotly plots into static image formats including PNG, JPEG, WEBP, SVG, and PDF. It achieves this by using WebDriver and headless browsers.
There are two main API styles:
- Old Style API: Creates a new
StaticExporterinstance for everywrite_imagecall. This is suitable for one-off exports. - New Style API (Recommended): Allows you to reuse a single
StaticExporterinstance across multiple exports, which is significantly more efficient for performance.
Both synchronous (StaticExporter) and asynchronous (AsyncStaticExporter) APIs are available via plotly::plotly_static when the appropriate static export features are enabled.