Skip to content

write_image Kaleido failed to generate static image #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
neo-escieur opened this issue Jan 8, 2025 · 12 comments
Open

write_image Kaleido failed to generate static image #270

neo-escieur opened this issue Jan 8, 2025 · 12 comments
Assignees
Labels
KaleidoRework Issue related to Kaleido dependency

Comments

@neo-escieur
Copy link

neo-escieur commented Jan 8, 2025

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 ?

@andrei-ng
Copy link
Collaborator

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
Copy link
Author

neo-escieur commented Jan 13, 2025

Same issue after deleting the locally downloaded and installed version of Kaleido and rebuilding.

@neo-escieur
Copy link
Author

more info:

thread 'main' panicked at C:\Users\xxxx\.cargo\registry\src\index.crates.io-6f17d22bba15001f\plotly_kaleido-0.12.1\src/lib.rs:40:38:
called `Result::unwrap()` on an `Err` value: Error("EOF while parsing a value", line: 1, column: 0)
stack backtrace:
   0:     0x7ff6719490b1 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ff6719490b1 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff6719490b1 - std::sys::backtrace::_print_fmt
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\backtrace.rs:66
   3:     0x7ff6719490b1 - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\backtrace.rs:39
   4:     0x7ff67196544a - core::fmt::rt::Argument::fmt
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/core\src\fmt\rt.rs:177
   5:     0x7ff67196544a - core::fmt::write
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/core\src\fmt\mod.rs:1186
   6:     0x7ff671945c27 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\io\mod.rs:1839
   7:     0x7ff671948ef5 - std::sys::backtrace::BacktraceLock::print
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\backtrace.rs:42
   8:     0x7ff67194ad67 - std::panicking::default_hook::closure$1
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:268
   9:     0x7ff67194ab47 - std::panicking::default_hook
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:295
  10:     0x7ff67194b3f3 - std::panicking::rust_panic_with_hook
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:801
  11:     0x7ff67194b279 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:674
  12:     0x7ff671949b6f - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\backtrace.rs:170
  13:     0x7ff67194ae7e - std::panicking::begin_panic_handler
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:665
  14:     0x7ff67196c7b1 - core::panicking::panic_fmt
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/core\src\panicking.rs:74
  15:     0x7ff67196cbe0 - core::result::unwrap_failed
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/core\src\result.rs:1700
  16:     0x7ff6718cb4a2 - enum2$<core::result::Result<plotly_kaleido::KaleidoResult,serde_json::error::Error> >::unwrap
                               at C:\Users\xxxx\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\result.rs:1104
  17:     0x7ff6718cb4a2 - plotly_kaleido::KaleidoResult::from
                               at C:\Users\xxxx\.cargo\registry\src\index.crates.io-6f17d22bba15001f\plotly_kaleido-0.12.1\src\lib.rs:40
  18:     0x7ff6718ccd69 - plotly_kaleido::Kaleido::convert
                               at C:\Users\xxxx\.cargo\registry\src\index.crates.io-6f17d22bba15001f\plotly_kaleido-0.12.1\src\lib.rs:229
  19:     0x7ff6718cbe86 - plotly_kaleido::Kaleido::save
                               at C:\Users\xxxx\.cargo\registry\src\index.crates.io-6f17d22bba15001f\plotly_kaleido-0.12.1\src\lib.rs:147
  20:     0x7ff67178456c - plotly::plot::Plot::write_image<ref$<str$> >
                               at C:\Users\xxxx\.cargo\registry\src\index.crates.io-6f17d22bba15001f\plotly-0.12.1\src\plot.rs:408
  21:     0x7ff6717bd5ea - tst1::main
                               at C:\Users\xxxx\Documents\tst1\src\main.rs:38
  22:     0x7ff67178328b - core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
                               at C:\Users\xxxx\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:250
  23:     0x7ff6717b9f0e - core::hint::black_box
                               at C:\Users\xxxx\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\hint.rs:389
  24:     0x7ff6717b9f0e - std::sys::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >
                               at C:\Users\xxxx\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\backtrace.rs:154
  25:     0x7ff6717b9c91 - std::rt::lang_start::closure$0<tuple$<> >
                               at C:\Users\xxxx\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs:195
  26:     0x7ff67194310c - std::rt::lang_start_internal::closure$1
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\rt.rs:174
  27:     0x7ff67194310c - std::panicking::try::do_call
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:557
  28:     0x7ff67194310c - std::panicking::try
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:520
  29:     0x7ff67194310c - std::panic::catch_unwind
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panic.rs:358
  30:     0x7ff67194310c - std::rt::lang_start_internal
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\rt.rs:174
  31:     0x7ff6717b9c6a - std::rt::lang_start<tuple$<> >
                               at C:\Users\xxxx\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs:194
  32:     0x7ff6717bd909 - main

@andrei-ng
Copy link
Collaborator

Thanks for the backtrace, I will let you know if I figure out a solution.

@andrei-ng andrei-ng self-assigned this Jan 22, 2025
@andrei-ng andrei-ng added the KaleidoRework Issue related to Kaleido dependency label Jan 31, 2025
@HerrMuellerluedenscheid
Copy link
Contributor

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
Copy link
Collaborator

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
Copy link
Contributor

HerrMuellerluedenscheid commented Apr 15, 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.

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.

Image

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
Copy link
Contributor

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
Copy link
Collaborator

@HerrMuellerluedenscheid , thanks for the investigation and attachements. I will try to find some time to look into this.

@HerrMuellerluedenscheid
Copy link
Contributor

HerrMuellerluedenscheid commented 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
Copy link
Collaborator

Sure! Thanks anyway for taking the time to look into it.

@HerrMuellerluedenscheid
Copy link
Contributor

Sure! Thanks anyway for taking the time to look into it.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
KaleidoRework Issue related to Kaleido dependency
Projects
None yet
Development

No branches or pull requests

3 participants