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
// Always close the exporter to ensure proper release of WebDriver resources
137
+
exporter.close();
132
138
```
133
139
140
+
Always call `close()` on the exporter to ensure proper release of WebDriver resources. Due to the nature of WebDriver implementation, close has to be called as resources cannot be automatically dropped or released.
141
+
134
142
## Advanced Configuration
135
143
136
144
### Custom WebDriver Configuration
@@ -150,6 +158,10 @@ let mut exporter = StaticExporterBuilder::default()
150
158
])
151
159
.build()
152
160
.expect("Failed to create StaticExporter");
161
+
162
+
// Always close the exporter to ensure proper release of WebDriver resources
163
+
exporter.close();
164
+
153
165
```
154
166
155
167
### Parallel Usage
@@ -172,8 +184,17 @@ let mut exporter = StaticExporterBuilder::default()
172
184
.webdriver_port(get_unique_port())
173
185
.build()
174
186
.expect("Failed to build StaticExporter");
187
+
188
+
// Always close the exporter to ensure proper release of WebDriver resources
189
+
exporter.close();
175
190
```
176
191
192
+
### Async support
193
+
194
+
`plotly_static` package offers an `async` API which can is exposed in `plotly` as well but only if the user passes an `AsyncStaticExporter` to the `write_image_async`, `to_base64_async` and `to_svg_async` functions. The `AsyncStaticExporter` can be built using the `StaticExportBuilder`'s `build_async` method.
195
+
196
+
For more details check the [`plotly_static` API Documentation](https://docs.rs/plotly_static/)
197
+
177
198
## Logging Support
178
199
179
200
Enable logging for debugging and monitoring:
@@ -190,6 +211,9 @@ env_logger::init();
190
211
letmutexporter=StaticExporterBuilder::default()
191
212
.build()
192
213
.expect("Failed to create StaticExporter");
214
+
215
+
// Always close the exporter to ensure proper release of WebDriver resources
216
+
exporter.close();
193
217
```
194
218
195
219
## Performance Considerations
@@ -200,7 +224,7 @@ let mut exporter = StaticExporterBuilder::default()
200
224
201
225
## Complete Example
202
226
203
-
See the [static export example](../../../examples/static_export/) for a complete working example that demonstrates:
227
+
See the [static export example](https://github.com/plotly/plotly.rs/tree/main/examples/static_export) for a complete working example that demonstrates:
Copy file name to clipboardExpand all lines: examples/static_export/README.md
+23-6Lines changed: 23 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,15 @@ The `plotly_static` provides a interface for converting Plotly plots into variou
6
6
7
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 across multiple exports.
8
8
9
-
See also the `Static Image Export` section in the book for a more detailed description.
9
+
There are both a sync and an async StaticExporter version which can be build with `build` and `build_async` methods.
10
10
11
-
## Overview
11
+
Refer to the [`plotly_static` API Documentation](https://docs.rs/plotly_static/) a more detailed description.
12
12
13
+
## Overview
13
14
14
15
## Features
15
16
17
+
-**Async/Sync API**
16
18
-**Multiple Export Formats**: PNG, JPEG, SVG, PDF
17
19
-**Exporter Reuse (new API)**: Efficient reuse of a single `StaticExporter` instance
18
20
-**String Export**: Base64 and SVG string output for web applications
@@ -45,17 +47,32 @@ plotly = { version = "0.13", features = ["static_export_geckodriver"] }
45
47
plotly = { version = "0.13", features = ["static_export_chromedriver"] }
46
48
```
47
49
48
-
## Running the Example
50
+
## Running the Example(s)
51
+
52
+
To run the `sync` API example
53
+
54
+
```bash
55
+
# Basic run
56
+
cargo run --bin sync
57
+
58
+
# With debug logging
59
+
RUST_LOG=debug cargo run --bin sync
60
+
61
+
# With custom WebDriver path
62
+
WEBDRIVER_PATH=/path/to/chromedriver cargo run --bin sync
63
+
```
64
+
65
+
To run the `async` API example
49
66
50
67
```bash
51
68
# Basic run
52
-
cargo run
69
+
cargo run --bin async
53
70
54
71
# With debug logging
55
-
RUST_LOG=debug cargo run
72
+
RUST_LOG=debug cargo run --bin async
56
73
57
74
# With custom WebDriver path
58
-
WEBDRIVER_PATH=/path/to/chromedriver cargo run
75
+
WEBDRIVER_PATH=/path/to/chromedriver cargo run --bin async
0 commit comments