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: README.md
+33-9Lines changed: 33 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,18 +96,38 @@ If you only want to view the plot in the browser quickly, use the `Plot.show()`
96
96
plot.show(); // The default web browser will open, displaying an interactive plot
97
97
```
98
98
99
-
## Exporting a Static Image
99
+
## Exporting Static Images with Kaleido
100
100
101
-
To save a plot as a static image, the `kaleido` feature is required:
101
+
To save a plot as a static image, the `kaleido` feature is required as well as installing an **external dependency**.
102
+
103
+
### Kaleido external dependency
104
+
105
+
When developing applications for your host, enabling both `kaleido` and `kaleido_download` features will ensure that the `kaleido` binary is downloaded for your system's architecture at compile time. After download, it is unpacked into a specific path, e.g., on Linux this is `/home/USERNAME/.config/kaleido`. With these two features enabled, static images can be exported as described in the next section as long as the application run on the same host where where this crate was compiled on.
106
+
107
+
When the applications developed with `plotly.rs` are intended for other targets or when the user wants to control where the `kaleido` binary is installed then Kaleido must be manually downloaded and installed. Setting the environment variable `KALEIDO_PATH=/path/installed/kaleido/` will ensure that applications that were built with the `kaleido` feature enabled can locate the `kaleido` executable and use it to generate static images.
108
+
109
+
Kaleido binaries are available on Github [release page](https://github.com/plotly/Kaleido/releases). It currently supports Linux(`x86_64`), Windows(`x86_64`) and MacOS(`x86_64`/`aarch64`).
110
+
111
+
## Exporting a Static Images
112
+
113
+
Enable the `kaleido` feature and opt in for automatic downloading of the `kaleido` binaries by doing the following
102
114
103
115
```toml
104
116
# Cargo.toml
105
117
118
+
[dependencies]
119
+
plotly = { version = "0.11", features = ["kaleido", "kaleido_download"] }
120
+
```
121
+
122
+
Alternatively, enable only the `kaleido` feature and manually install Kaleido.
123
+
```toml
124
+
# Cargo.toml
125
+
106
126
[dependencies]
107
127
plotly = { version = "0.11", features = ["kaleido"] }
108
128
```
109
129
110
-
With this feature enabled, plots can be saved as any of `png`, `jpeg`, `webp`, `svg`, `pdf` and `eps`. Note that the plot will be a static image, i.e. they will be non-interactive.
130
+
With the feature enabled, plots can be saved as any of `png`, `jpeg`, `webp`, `svg`, `pdf` and `eps`. Note that the plot will be a static image, i.e. they will be non-interactive.
On your host, when building this project with the `kaleido` feature enabled the Kaleido binary is downloaded automatically for your system's architecture at compile time from the official Kaleido [release page](https://github.com/plotly/Kaleido/releases). This library currently supports `x86_64` on Linux and Windows, and both `x86_64` and `aarch64` on macOS.
127
-
128
-
When building application for other targets that depend on this feature, the `Kaleido` binary will need to be installed manually on the target machine. Currently, the location where the binary is expected is hardcoded depending on the target OS. E.g., on Linux this defaults to `~/.config/kaleido`. This is defined in source code [here](https://github.com/plotly/plotly.rs/blob/1405731b5121c1343b491e307222a21ef4becc5e/plotly_kaleido/src/lib.rs#L89)
129
-
130
144
## Usage Within a Wasm Environment
131
145
132
146
Using `Plotly.rs` in a Wasm-based frontend framework is possible by enabling the `wasm` feature:
@@ -198,6 +212,16 @@ The following feature flags are available:
198
212
199
213
Adds plot save functionality to the following formats: `png`, `jpeg`, `webp`, `svg`, `pdf` and `eps`.
200
214
215
+
Requires `Kaleido` to have been previously installed on the host machine. See below feature flag and [click on this link](#my-multi-word-header).
216
+
217
+
### `kaleido_download`
218
+
219
+
Enable download and install of Kaleido binary at build time from [Kaleido releases](https://github.com/plotly/Kaleido/releases/) on the host machine.
220
+
221
+
222
+
223
+
This will ensure that your applications can export plots to static images on the host machine. However, when porting your applications to a different machine, `Kaleido` will have to be installed manually. See [Setting up Kaleido](#my-multi-word-header).
224
+
201
225
### `plotly_image`
202
226
203
227
Adds trait implementations so that `image::RgbImage` and `image::RgbaImage` can be used more directly with the `plotly::Image` trace.
println!("Use `kaleido_fetch` feature to automatically download, install and use Kaleido when targeting applications that run on the host machine.");
90
+
println!("Use `kaleido_download` feature to automatically download, install and use Kaleido when targeting applications that run on the host machine.");
91
91
println!("Use `{}` environment variable when targeting applications intended to run on different machines. Manually install Kaleido on the target machine and point {} to the installation location.",Self::KALEIDO_PATH_ENV,Self::KALEIDO_PATH_ENV
92
92
);
93
93
std::process::exit(1);
@@ -199,6 +199,7 @@ impl Kaleido {
199
199
"--single-process",
200
200
"--disable-gpu",
201
201
"--no-sandbox",
202
+
"--enable-logging",
202
203
])
203
204
.stdin(Stdio::piped())
204
205
.stdout(Stdio::piped())
@@ -227,22 +228,19 @@ impl Kaleido {
227
228
let output_lines = BufReader::new(process.stdout.take().unwrap()).lines();
228
229
for line in output_lines.map_while(Result::ok){
229
230
let res = KaleidoResult::from(line.as_str());
230
-
match res.result{
231
-
Some(image_data) => {
232
-
// TODO: this should be refactored
233
-
// The assumption is that KaleidoResult contains a single image.
234
-
// We should end the loop on the first valid one.
235
-
// If that is not the case, prior implementation would have returned the last
236
-
// valid image
237
-
returnOk(image_data);
238
-
}
239
-
None => {
240
-
println!("empty line from Kaleido stdout");
241
-
}
231
+
ifletSome(image_data) = res.result{
232
+
// TODO: this should be refactored
233
+
// The assumption is that KaleidoResult contains a single image.
234
+
// We should end the loop on the first valid one.
235
+
// If that is not the case, prior implementation would have returned the last
236
+
// valid image
237
+
returnOk(image_data);
242
238
}
243
239
}
244
240
245
-
// Don't eat up Kaleido/Chromiu erros but show them in the terminal
241
+
// Don't eat up Kaleido/Chromium errors but show them in the terminal
242
+
println!("Kaleido failed to generate static image for format: {format}.");
243
+
println!("Kaleido stderr output:");
246
244
let stderr = process.stderr.take().unwrap();
247
245
let stderr_lines = BufReader::new(stderr).lines();
0 commit comments