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
+20-7Lines changed: 20 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,16 @@ plot.show(); // The default web browser will open, displaying an interactive plo
98
98
99
99
## Exporting a Static Image
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`.
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 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`).
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
133
## Usage Within a Wasm Environment
131
134
132
135
Using `Plotly.rs` in a Wasm-based frontend framework is possible by enabling the `wasm` feature:
@@ -198,6 +201,16 @@ The following feature flags are available:
198
201
199
202
Adds plot save functionality to the following formats: `png`, `jpeg`, `webp`, `svg`, `pdf` and `eps`.
200
203
204
+
Requires `Kaleido` to have been previously installed on the host machine. See below feature flag and [click on this link](#my-multi-word-header).
205
+
206
+
### `kaleido_download`
207
+
208
+
Enable download and install of Kaleido binary at build time from [Kaleido releases](https://github.com/plotly/Kaleido/releases/) on the host machine.
209
+
210
+
211
+
212
+
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).
213
+
201
214
### `plotly_image`
202
215
203
216
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
+
"--debug",
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