docs.rs failed to build plotly_static-0.0.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
plotly_static
Export Plotly plots to static images using WebDriver and headless browsers.
Overview
plotly_static
provides a Rust interface for converting Plotly plots from JSON data into various static image formats (PNG, JPEG, WEBP, SVG, PDF) using WebDriver and headless browsers.
Features
- Multiple Formats: PNG, JPEG, WEBP, SVG, PDF
- Browser Support: Chrome/Chromium (chromedriver) and Firefox (geckodriver)
- Efficient: Reuse
StaticExporter
instances for multiple exports - String Export: Base64 and SVG output for web applications
- Parallel Safe: Designed for concurrent usage
- Automatic Management: Handles WebDriver lifecycle and cleanup
Quick Start
use ;
use json;
use Path;
// Create a simple plot as JSON
let plot = json!;
// Build and use StaticExporter
let mut exporter = default
.build
.expect;
// Export to PNG
exporter.write_fig.expect;
Usage
Add to your Cargo.toml
:
[]
= { = "0.0.1", = ["chromedriver", "webdriver_download"] }
= "1.0"
Feature Flags
chromedriver
: Use Chromedriver and Chrome/Chromium browser for rendering and exportgeckodriver
: Use Geckodriver Firefox browser for rendering for rendering and exportwebdriver_download
: Auto-download the chosen WebDriver binary
Prerequisites
- Browser: Chrome/Chromium or Firefox installed
- WebDriver: Manually installed or automatically downloaded and installed with the
webdriver_download
feature - Internet Connectivity: Required for WebDriver download when using the auto-download and install feature
Advanced Usage
Static Exporter Reuse
use ;
use json;
use Path;
let plot1 = json!;
let plot2 = json!;
let mut exporter = default
.build
.expect;
// Reuse for multiple exports
exporter.write_fig?;
exporter.write_fig?;
String Export
use ;
use json;
let plot = json!;
let mut exporter = default
.build
.expect;
// Get base64 data for web embedding
let base64_data = exporter.write_to_string?;
// Get SVG data (vector format)
let svg_data = exporter.write_to_string?;
Custom Configuration
use StaticExporterBuilder;
let mut exporter = default
.webdriver_port // Unique port for parallel usage
.offline_mode // Use bundled JavaScript
.webdriver_browser_caps
.build?;
Environment Variables
WEBDRIVER_PATH
: Custom WebDriver binary locationBROWSER_PATH
: Custom browser binary location
Examples
Check the self contatined examples in the examples folder.
Similar examples are available in the Plotly.rs package, in Plotly.rs Book as well as the example in Plotly.rs examples/static_export.
Documentation
License
This package is licensed under the MIT License.