Open
Description
On Windows:
with this in Cargo.toml:
[dependencies]
plotly = { version = "0.12.1", features = ["kaleido", "kaleido_download"] }
rand = "0.8.5"
rand_distr = "0.4.3"
and this code :
use plotly::{
color::{NamedColor},
common::{ Marker },
layout::{Layout, BarMode},
Histogram, Plot, ImageFormat
};
use rand_distr::{Distribution, Normal};
fn sample_normal_distribution(n: usize, mean: f64, std_dev: f64) -> Vec<f64> {
let mut rng = rand::thread_rng();
let dist = Normal::new(mean, std_dev).unwrap();
let mut v = Vec::<f64>::with_capacity(n);
for _idx in 1..n {
v.push(dist.sample(&mut rng));
}
v
}
fn main() {
let samples1 = sample_normal_distribution(500, 0.0, 1.0);
let trace1 = Histogram::new(samples1)
.name("trace 1")
.opacity(0.5)
.marker(Marker::new().color(NamedColor::Green));
let samples2 = sample_normal_distribution(500, 0.0, 1.0);
let trace2 = Histogram::new(samples2)
.name("trace 2")
.opacity(0.6)
.marker(Marker::new().color(NamedColor::Red));
let mut plot = Plot::new();
plot.add_trace(trace1);
plot.add_trace(trace2);
let layout = Layout::new().bar_mode(BarMode::Stack);
plot.set_layout(layout);
plot.write_html("out.html");
plot.write_image("testx", ImageFormat::PNG, 800, 600, 1.0);
}
the file out.html is ok but testx.png is created but empty.
this is the error:
Kaleido failed to generate static image for format: png.
Kaleido stderr output:
[0108/174710.543:WARNING:resource_bundle.cc(405)] locale_file_path.empty() for locale
[0108/174710.605:WARNING:headless_browser_main_parts.cc(83)] Cannot create Pref Service with no user data dir.
is there a way to make this working on windows ?
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
andrei-ng commentedon Jan 13, 2025
Could you try to remove the locally downloaded and installed version of Kaleido and try to build the crate and your example again.
Kaleido is a tough cookie . I will try to reproduce and debug in the CI (don't own a Windows machine)
neo-escieur commentedon Jan 13, 2025
Same issue after deleting the locally downloaded and installed version of Kaleido and rebuilding.
neo-escieur commentedon Jan 13, 2025
more info:
andrei-ng commentedon Jan 19, 2025
Thanks for the backtrace, I will let you know if I figure out a solution.
HerrMuellerluedenscheid commentedon Feb 25, 2025
I run into the same issue. Seems to be a problem of truncated result data used in
KaleidoResult::from(result: &str)
.With a little debug info I'm seeing that it actually raises a
Error("EOF while parsing a string", line: 1, column: 16384)
an what looks like a really large truncated response which serde_json then fails to serialize.andrei-ng commentedon Feb 25, 2025
That is interesting. Can you share the plot you were building as an example. So I could try to reproduce and debug further next time I look into it.
HerrMuellerluedenscheid commentedon Apr 15, 2025
The Problem is it is quite random when it fails. I'm attaching an image where the export to PNG worked fine but kaleido crashed when converting the same image to PDF. However, the exact same processing works fine most of the time and only crashes occasionally with the above mentioned truncation.
There are the two NaN s in the legend but it also crashes when those are not displayed. So that is not the issue as one might think.
HerrMuellerluedenscheid commentedon Apr 15, 2025
The attached archive contains three times the same image as png, pdf and raw html generated with plotly. In a first run kaleido crashed with the above mentioned on error on pdf conversion but wrote the html and png. On a second try all worked fine and generated the pdf. It's super enigmatic.
Archive.zip
andrei-ng commentedon Apr 15, 2025
@HerrMuellerluedenscheid , thanks for the investigation and attachements. I will try to find some time to look into this.
HerrMuellerluedenscheid commentedon Apr 15, 2025
After reading #kaleido I should note that I'm on M1. Thus, the problems I'm encountering may be related to that. I guess I will switch to plotters for the time as an interim solution and check back later when the rework of kaleido is done.
andrei-ng commentedon Apr 15, 2025
Sure! Thanks anyway for taking the time to look into it.
HerrMuellerluedenscheid commentedon Apr 15, 2025
Sure thing. If there is something that I should test on my M1 along the way I'm happy to do that. Just drop me a message.
andrei-ng commentedon Jul 7, 2025
@HerrMuellerluedenscheid, @neo-escieur , I've implemented a different approach to perform exports using WebDriver.
The latest release has now a new package
plotly_static
that drives a browser using WebDriver to do the static export.I've tested it in the CI pipeline for Windows, MacOS and Ubuntu. On the Windows runners it is a bit flaky, but on Linux and MacOS runners seems to be stable.
This has been introduced in PR #319, would you guys be willing to test it out and give me some feedback on it?