MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.41k stars 312 forks source link

VSCode notebook viewer not implemented #2989

Open georgematheos opened 1 year ago

georgematheos commented 1 year ago

Consider the following 2-cell Jupyter notebook: Cell 1:

using WGLMakie

Cell 2:

scatter(1:3, 1:3)

If I enter and run these two cells in an unsaved Jupyter notebook, in the VSCode Jupyter notebook viewer, a scatter plot is displayed.

Issue 1: If I enter and run these two cells in a Jupyter notebook saved under some filename, using the VSCode Jupyter notebook viewer, the cells appear to run, but no scatter plot is displayed. (Other times when I do this, the scatter cell appears to run indefinitely. I am not sure what the difference is between the times when the cell finishes executing without displaying anything, and when the cell appears to infinite-loop.)

Possible issue 2: If I add a cell at the top of the notebook, with the code

using JSServe
Page()

(which the documentation appears to suggest), then executing scatter(1:3, 1:3) (or any line of code which should result in a WGLMakie plot being displayed) appears to run indefinitely. (I am not sure we are supposed to add a Page, in this case, but if not perhaps this should be clarified in the documentation.)

georgematheos commented 1 year ago

Update: Now, when I run the unsaved Jupyter notebook in the VSCode notebook viewer, the scatter call appears to infinite loop. I'm not sure what changed since when I was using this earlier.

SimonDanisch commented 1 year ago

VSCode notebook viewer isn't tested at all with JSServe right now, so this is somewhat expected. This will need some focused effort to make sure it works correctly. Sadly, every notebook system has very different ways to include & render the html, so impossible to make JSServe work out of the box for every system :(

kbarros commented 10 months ago

Bummer that this is so non-standardized.

In my tests, attempts to plot to VSCode/notebook often seems to hang for a long time. If interrupted, it prints this stack trace:

InterruptException:

Stacktrace:
  [1] process_events
    @ Base [./libuv.jl:119](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/libuv.jl:119) [inlined]
  [2] wait()
    @ Base [./task.jl:996](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/task.jl:996)
  [3] yield()
    @ Base [./task.jl:875](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/task.jl:875)
  [4] get_three(screen::WGLMakie.Screen; timeout::Int64, error::Nothing)
    @ WGLMakie [~/.julia/packages/WGLMakie/XT8NJ/src/display.jl:220](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/~/.julia/packages/WGLMakie/XT8NJ/src/display.jl:220)
  [5] get_three
    @ WGLMakie [~/.julia/packages/WGLMakie/XT8NJ/src/display.jl:200](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/~/.julia/packages/WGLMakie/XT8NJ/src/display.jl:200) [inlined]
  [6] wait_for_display(screen::WGLMakie.Screen)
    @ WGLMakie [~/.julia/packages/WGLMakie/XT8NJ/src/display.jl:260](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/~/.julia/packages/WGLMakie/XT8NJ/src/display.jl:260)
  [7] display(figlike::Makie.FigureAxisPlot; backend::Module, inline::MakieCore.Automatic, update::Bool, screen_config::@Kwargs{})
    @ Makie [~/.julia/packages/Makie/Qvk4f/src/display.jl:153](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/~/.julia/packages/Makie/Qvk4f/src/display.jl:153)
  [8] display(figlike::Makie.FigureAxisPlot)
    @ Makie [~/.julia/packages/Makie/Qvk4f/src/display.jl:130](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/~/.julia/packages/Makie/Qvk4f/src/display.jl:130)
  [9] #invokelatest#2
    @ [./essentials.jl:887](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/essentials.jl:887) [inlined]
 [10] invokelatest
    @ [./essentials.jl:884](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/essentials.jl:884) [inlined]
 [11] (::VSCodeServer.var"#208#209"{VSCodeServer.NotebookRunCellArguments, String})()
    @ VSCodeServer [~/.vscode/extensions/julialang.language-julia-1.65.2/scripts/packages/VSCodeServer/src/serve_notebook.jl:48](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/~/.vscode/extensions/julialang.language-julia-1.65.2/scripts/packages/VSCodeServer/src/serve_notebook.jl:48)
...
    @ VSCodeServer.JSONRPC [~/.vscode/extensions/julialang.language-julia-1.65.2/scripts/packages/JSONRPC/src/typed.jl:67](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/~/.vscode/extensions/julialang.language-julia-1.65.2/scripts/packages/JSONRPC/src/typed.jl:67)
 [15] serve_notebook(pipename::String, outputchannel_logger::Base.CoreLogging.SimpleLogger; crashreporting_pipename::String)
    @ VSCodeServer [~/.vscode/extensions/julialang.language-julia-1.65.2/scripts/packages/VSCodeServer/src/serve_notebook.jl:139](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/~/.vscode/extensions/julialang.language-julia-1.65.2/scripts/packages/VSCodeServer/src/serve_notebook.jl:139)
 [16] top-level scope
    @ [~/.vscode/extensions/julialang.language-julia-1.65.2/scripts/notebook/notebook.jl:32](https://file+.vscode-resource.vscode-cdn.net/Users/kbarros/.julia/dev/Sunny/~/.vscode/extensions/julialang.language-julia-1.65.2/scripts/notebook/notebook.jl:32)
kbarros commented 10 months ago

As a temporary workaround for this problem (and also maybe https://github.com/MakieOrg/Makie.jl/issues/3117 and https://github.com/MakieOrg/Makie.jl/issues/2405) is it possible for WGLMakie to detect an "unsupported context"? In this case, WGLMakie could send the figure to a fresh web browser tab, where Makie has full control? This would be a better user experience for new Julia users, who may not be familiar with WGLMakie subtleties.