Skip to content
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

Plot show Method Not Working on Windows 10 #132

Open
M-NK-Y opened this issue Jan 21, 2023 · 7 comments
Open

Plot show Method Not Working on Windows 10 #132

M-NK-Y opened this issue Jan 21, 2023 · 7 comments

Comments

@M-NK-Y
Copy link
Contributor

M-NK-Y commented Jan 21, 2023

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

M-NK-Y commented Jan 21, 2023

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

M-NK-Y commented Jan 21, 2023

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

@Foobin
Copy link

Foobin commented Mar 24, 2023

Confirmed not working on Windows 11 as well.

@fsktom
Copy link

fsktom commented Mar 29, 2023

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 added a commit to fsktom/rusty-endsong-parser that referenced this issue Mar 29, 2023
fsktom added a commit to fsktom/rusty-endsong-parser that referenced this issue Mar 29, 2023
@mfreeborn
Copy link
Contributor

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

@fsktom
Copy link

fsktom commented Apr 1, 2023

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

@madpower2000
Copy link

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.

mfreeborn pushed a commit that referenced this issue Jul 9, 2023
…#133)

* Changes to `show` method for Windows

* `CHANGELOG.md` PR credits updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants