You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/static_export/README.md
+19-21Lines changed: 19 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,29 @@
1
1
# Static Export Example
2
2
3
-
This example demonstrates how to use the `plotly_static` crate for exporting Plotly plots to static images using WebDriver and headless browsers. See also the `Static Image Export` section in the book for a more detailed description.
3
+
This example demonstrates how to use the `plotly_static` crate for exporting Plotly plots to static images.
4
+
5
+
The `plotly_static` provides a interface for converting Plotly plots into various static image formats (PNG, JPEG, WEBP, SVG, PDF) using WebDriver and headless browsers.
6
+
7
+
In this example it is shown how to use the `StaticExporter` with the old style Kaleido API and also with the new style API. Using the former API is fine for one time static exports, but that API will crate an instance of the `StaticExporter` for each `write_image` call. The new style API is recommended for performance as the same instance of the `StaticExporter` can be reused accross mutliple exports.
8
+
9
+
See also the `Static Image Export` section in the book for a more detailed description.
4
10
5
11
## Overview
6
12
7
-
The `plotly_static` crate provides a high-level interface for converting Plotly JSON plots into various static image formats (PNG, JPEG, WEBP, SVG, PDF) using WebDriver and headless browsers.
8
13
9
-
## Features Demonstrated
14
+
## Features
10
15
11
16
-**Multiple Export Formats**: PNG, JPEG, SVG, PDF
12
-
-**Exporter Reuse**: Efficient reuse of a single `StaticExporter` instance
17
+
-**Exporter Reuse (new API)**: Efficient reuse of a single `StaticExporter` instance
13
18
-**String Export**: Base64 and SVG string output for web applications
14
19
-**Logging**: Debug information and progress monitoring
15
-
-**Error Handling**: Proper error handling with `Result` types
20
+
-**Error Handling**: Error handling with `Result` types
16
21
17
22
## Prerequisites
18
23
19
24
1.**Browser Installation**: You need either Firefox (for geckodriver) or Chrome/Chromium (for chromedriver)
20
-
2.**WebDriver**: Automatically downloaded with the `static_export_default` feature
21
-
3.**Internet Connection**: Required for initial WebDriver download (if using `webdriver_download` feature)
25
+
2.**WebDriver**: Chromedriver automatically downloaded with the `static_export_default` feature
26
+
3.**Internet Connection**: Required for WebDriver download (if using `webdriver_download` feature)
22
27
23
28
## Feature Flags
24
29
@@ -30,13 +35,13 @@ The example uses `static_export_default` which includes:
30
35
### Alternative Configurations
31
36
32
37
```toml
33
-
# Use Chrome/Chromium instead of Firefox
34
-
plotly = { version = "0.13", features = ["static_export_chromedriver", "static_export_wd_download"] }
38
+
# Use Firefox instead of Chrome/Chromium
39
+
plotly = { version = "0.13", features = ["static_export_geckodriver", "static_export_wd_download"] }
35
40
36
-
# Manual WebDriver installation (no automatic download)
41
+
# Manual Geckodriver installation (no automatic download)
37
42
plotly = { version = "0.13", features = ["static_export_geckodriver"] }
38
43
39
-
#Chrome with manual installation
44
+
#Manual Chromedriver installation (no automatic download)
40
45
plotly = { version = "0.13", features = ["static_export_chromedriver"] }
41
46
```
42
47
@@ -50,7 +55,7 @@ cargo run
50
55
RUST_LOG=debug cargo run
51
56
52
57
# With custom WebDriver path
53
-
WEBDRIVER_PATH=/path/to/geckodriver cargo run
58
+
WEBDRIVER_PATH=/path/to/chromedriver cargo run
54
59
```
55
60
56
61
## Output
@@ -61,17 +66,11 @@ The example generates several files:
61
66
-`plot3.svg`: Vector format, scalable, good for web
62
67
-`plot1.pdf`: Vector format, good for printing
63
68
64
-
## Performance Tips
65
-
66
-
1.**Reuse Exporters**: Create a single `StaticExporter` and reuse it for multiple plots
67
-
2.**Parallel Usage**: Use unique ports for parallel operations (tests, etc.)
68
-
3.**Resource Management**: The exporter automatically manages WebDriver lifecycle
69
-
70
69
## Advanced Configuration
71
70
72
71
The example includes commented code showing advanced configuration options:
73
72
- Custom WebDriver ports for parallel usage
74
-
- Offline mode for bundled JavaScript
73
+
- Offline mode for bundled JavaScript
75
74
- Custom browser capabilities
76
75
- Explicit WebDriver spawning
77
76
@@ -81,11 +80,10 @@ The example includes commented code showing advanced configuration options:
81
80
82
81
1.**WebDriver not found**: Ensure the browser is installed and WebDriver is available
83
82
2.**Port conflicts**: Use unique ports for parallel operations
84
-
3.**Permission errors**: Ensure WebDriver has execute permissions
85
83
86
84
### Debug Information
87
85
88
-
Set `RUST_LOG=debug` to see detailed WebDriver operations and troubleshooting information.
86
+
Set `RUST_LOG=debug`or`RUST_LOG=trace`to see detailed WebDriver operations and troubleshooting information.
0 commit comments