plotly.rs icon indicating copy to clipboard operation
plotly.rs copied to clipboard

Plot `show` Method Not Working on Windows 10

Open M-NK-Y opened this issue 2 years ago • 11 comments
trafficstars

MWE is given from excerpt within plot.rs:

use plotly::common::Mode;
use plotly::{Layout, Plot, Scatter};

fn line_and_scatter_plot() {
    let trace1 = Scatter::new(vec![1, 2, 3, 4], vec![10, 15, 13, 17])
        .name("trace1")
        .mode(Mode::Markers);
    let trace2 = Scatter::new(vec![2, 3, 4, 5], vec![16, 5, 11, 9])
        .name("trace2")
        .mode(Mode::Lines);
    let trace3 = Scatter::new(vec![1, 2, 3, 4], vec![12, 9, 15, 12])
        .name("trace3");

    let mut plot = Plot::new();
    plot.add_trace(trace1);
    plot.add_trace(trace2);
    plot.add_trace(trace3);

    let layout = Layout::new().title("<b>Line and Scatter Plot</b>".into());
    plot.set_layout(layout);

   # if false {  // We don't actually want to try and display the plot in a browser when running a doctest.
   plot.show();                                                                                            
   # }                                                                                                     
}

fn main() -> std::io::Result<()> {
    line_and_scatter_plot();
    Ok(())
}

Expected: Generated HTML to be opened using the user's default browser. Actual: System exits with code 0, though no process is spawned/made apparent.


At a glance the issue here seems to be with the parameters used when attempting to open the browser and more specifically their formatting (possibly a quirk of using the older syntax affected by the now closed issue #29494 or alternatively, regarding how the output method is being handled on Windows).

As an aside I'd imagine this probably went undetected for some time courtesy of:

"// We don't actually want to try and display the plot in a browser when running a doctest."

but this is just speculation and fortunately this can be hastily remedied and I'll open a PR for shortly.

Thanks! ❤️

M-NK-Y avatar Jan 21 '23 03:01 M-NK-Y

Just thought I'd leave an addendum here, I think there could be some kind of versioning issue because per #131 this should be fixed but unfortunately this appears to still be an issue as of version 0.8.4.

M-NK-Y avatar Jan 21 '23 03:01 M-NK-Y

Edit: Updated description within PR, but may be duplicate of #129 if updated args syntax isn't desirable.

M-NK-Y avatar Jan 21 '23 04:01 M-NK-Y

Confirmed not working on Windows 11 as well.

Foobin avatar Mar 24 '23 20:03 Foobin

I have the same problem. https://github.com/igiagkiozis/plotly/blob/8903ff03ce9e8183624c40ccf7ddf863799cb92e/plotly/src/plot.rs#L274

https://github.com/igiagkiozis/plotly/blob/8903ff03ce9e8183624c40ccf7ddf863799cb92e/plotly/src/plot.rs#L470-L478

I didn't try this out here, but in my own project and using explorer.exe instead of cmd.exe works for me. So

 #[cfg(target_os = "windows")] 
 fn show_with_default_app(temp_path: &str) { 
     use std::process::Command; 
     Command::new("explorer") 
         .arg(temp_path) 
         .output() 
         .expect(DEFAULT_HTML_APP_NOT_FOUND); 
 } 

should technically work?

edit: Oh, just noticed the PR - if #133 works fine, then that's great!

fsktom avatar Mar 29 '23 16:03 fsktom

@Foobin @fsktom - would you be able to confirm whether #133 fixes your problem?

mfreeborn avatar Apr 01 '23 16:04 mfreeborn

@mfreeborn just tried it out and the plot is opened without any problems in the browser on Windows 11 :D

fsktom avatar Apr 01 '23 18:04 fsktom

Don’t work out the box on my Windows 11. Seems like a problem with temp files, if I supply my own html file, it works fine. I use this workaround for now.

madpower2000 avatar Jun 07 '23 13:06 madpower2000