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

Plots in VSCode Jupyter notebook opens in browser instead of below cell #34

Closed
Titas22 opened this issue Nov 14, 2023 · 13 comments
Closed

Comments

@Titas22
Copy link
Contributor

Titas22 commented Nov 14, 2023

Hi,

I'm trying to use the example plot script, however I end up with the plot opening up in the browser instead of below the cell in Jupyter notebook in VSCode.

using PlotlyLight

p = Plot(x = 1:20, y = cumsum(randn(20)), type="scatter", mode="lines+markers")  # Make plot

display(p)

The output of that is:

Process(`'C:\WINDOWS\system32\cmd.exe' /c start '%USERPROFILE%\.julia\scratchspaces\ec354790-cf28-43e8-bb59-b484409b7bad\CobWeb\index.html'`, ProcessRunning)

Running the same code in REPL creates the plot in a window withing VSCode which is how I would expect it to behave.

I'm running on Windows:
Julia v1.9.0
VSCode v1.82.3
PlotlyLight v0.7.4

@joshday
Copy link
Member

joshday commented Nov 14, 2023

Hmm, that's a little surprising. What happens if you remove the display(p) part of the cell?

@Titas22
Copy link
Contributor Author

Titas22 commented Nov 14, 2023

Hmm, that's a little surprising. What happens if you remove the display(p) part of the cell?

No change, still opens up the browser. Think I might have left it in there after trying different stuff out to get it to work 😅

@joshday
Copy link
Member

joshday commented Nov 14, 2023

Okay, can you try running PlotlyLight.Preset.PlotContainer.iframe!() before the plot cell? Does that fix it?

@Titas22
Copy link
Contributor Author

Titas22 commented Nov 14, 2023

PlotlyLight.Preset.PlotContainer.iframe!()

Doesn't fix it. Still plots in the browser but now in a frame

@joshday
Copy link
Member

joshday commented Nov 15, 2023

My guess here is that there is an upstream issue, since this doesn't display anything:

HTML(repr("text/html", Plot(x=1:10)))

It's possible that VSCode's Jupyter disables the javascript that the plot's show method depends on.

@Titas22
Copy link
Contributor Author

Titas22 commented Nov 15, 2023

HTML(repr("text/html", Plot(x=1:10)))

Actually, this one worked:
image

@Titas22
Copy link
Contributor Author

Titas22 commented Nov 16, 2023

Although, tried it on another machine and as you said it did nothing (same versions of PlotlyLight and Julia, but VSCode 1.84.1)

@joshday
Copy link
Member

joshday commented Nov 16, 2023

I think it works if you run Preset.PlotContainer.iframe!(), but PlotlyLight isn't (yet) able to determine that it should do this automatically if you're running inside a VSCode Jupyter notebook.

@Titas22
Copy link
Contributor Author

Titas22 commented Nov 16, 2023

You're right, but I swear it worked without it on the other machine after kernel restart. Not on this one though.

@Titas22
Copy link
Contributor Author

Titas22 commented Nov 16, 2023

Think you might be able to use isdefined(Main, :VSCodeServer) to check if it's running from VSCode. It does return true both from REPL and Jupyter notebooks though

@Titas22
Copy link
Contributor Author

Titas22 commented Nov 23, 2023

HI @joshday, the above pull request above solves this for me in VSCode (and still works correctly in REPL), I don't have a way to test it on other systems but don't see why it would break anything. Could you review and merge it if you're happy please?

@joshday
Copy link
Member

joshday commented Nov 23, 2023

Same as the other issue: PR is in your own fork and not here.

@joshday
Copy link
Member

joshday commented Feb 5, 2024

Fixed on master/in v0.8.0

@joshday joshday closed this as completed Feb 5, 2024
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

Successfully merging a pull request may close this issue.

2 participants