cjdoris / Bokeh.jl

Interactive plotting made easy
https://cjdoris.github.io/Bokeh.jl
Other
77 stars 3 forks source link

Using a system image with Bokeh not working #19

Closed ufechner7 closed 1 year ago

ufechner7 commented 1 year ago

If you check out the repo at https://github.com/ufechner7/Plotting2 and follow the instructions in the README.md file, when using the created system image there is no error message, but the backend BokehBlink is not longer recognized and you just get some output in the console. No plot window is shown.

cjdoris commented 1 year ago

What output do you get when you call plot? Presumably the tree of the Plot model.

Most likely the Blink backend is not actually being set for some reason. Try putting @show Bokeh.SETTINGS.display in various places to see what the display backend is.

You could also try just calling Blink.Window() to see if you can make a Blink window without doing any plotting.

ufechner7 commented 1 year ago

Output when calling include("src/plot.jl"):

asysimg> include("src/plot.jl")
Figure:
  below = [
    LinearAxis: (blank)
  ]
  center = [
    Grid:
      axis = ...
      dimension = 0
    Grid:
      axis = LinearAxis: (blank)
      dimension = 1
  ]
  height = 700
  left = [
    ...
  ]
  renderers = [
    GlyphRenderer:
      data_source = ColumnDataSource:
        data = Dict(
          "x" => [
            0.0
            0.01
            0.02
            0.03
            0.04
            ...
          ]
          "y" => [
            0.0
            0.009999833334166664
            0.01999866669333308
            0.02999550020249566
            0.03998933418663416
            ...
          ]
        )
      glyph = Line:
        line_color = "#0000ff"
        line_width = 2.0
        x = Field("x")
        y = Field("y")
      view = CDSView:
        source = ...
  ]
  sizing_mode = "fixed"
  toolbar = Toolbar:
    tools = [
      PanTool: (blank)
      BoxZoomTool: (blank)
      WheelZoomTool: (blank)
      SaveTool: (blank)
      ResetTool: (blank)
      ...
    ]
  width = 1200
  x_range = DataRange1d: (blank)
  x_scale = LinearScale: (blank)
  y_range = DataRange1d: (blank)
  y_scale = LinearScale: (blank)

asysimg> 
ufechner7 commented 1 year ago
asysimg> BokehBlink.Window()
ERROR: MethodError: no method matching BokehBlink.Window()
Closest candidates are:
  BokehBlink.Window(::Blink.AtomShell.Window) at ~/.julia/packages/BokehBlink/LJnMy/src/BokehBlink.jl:36
  BokehBlink.Window(::Blink.AtomShell.Window, ::Vector{Bokeh.Resource}) at ~/.julia/packages/BokehBlink/LJnMy/src/BokehBlink.jl:32
  BokehBlink.Window(::Any, ::Any) at ~/.julia/packages/BokehBlink/LJnMy/src/BokehBlink.jl:32
Stacktrace:
 [1] top-level scope
   @ REPL[4]:1

asysimg> Blink.Window()
ERROR: UndefVarError: Blink not defined
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1
asysimg> @show Bokeh.SETTINGS.display
Bokeh.SETTINGS.display = BokehBlink.BlinkDisplayBackend()
BokehBlink.BlinkDisplayBackend()

To be honest, the relationship between Blink and BokehBlink is not clear to me...

cjdoris commented 1 year ago

You'll need to add the Blink package first.

Please add that @show line into your plot function, to see what backend is active when you actually display the plot. It appears that the Blink backend is not being activated for some reason.

ufechner7 commented 1 year ago

You'll need to add the Blink package first.

Why should I add the Blink package if it works (without custom system image) just with the BokehBlink package?

OK, I did it just for you and got the following result: A window opens and on the REPL I see:

asysimg> Blink.Window()
Window(1, Electron(Process(`/home/ufechner/.julia/packages/Blink/mwJC9/deps/atom/electron /home/ufechner/.julia/packages/Blink/mwJC9/src/AtomShell/main.js port 6909`, ProcessRunning), Sockets.TCPSocket(RawFD(23) active, 0 bytes waiting), Dict{String, Any}("callback" => Blink.var"#1#2"())), Page(1, WebSocket(server, CONNECTED), Dict{String, Any}("webio" => Blink.AtomShell.var"#22#23"{Blink.AtomShell.WebIOBlinkComm}(Blink.AtomShell.WebIOBlinkComm(Window(#= circular reference @-5 =#))), "callback" => Blink.var"#1#2"()), Distributed.Future(1, 1, 1, ReentrantLock(nothing, 0x00000000, 0x00, Base.GenericCondition{Base.Threads.SpinLock}(Base.InvasiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), (0, 139869488225280, 11)), Some(true))), Task (done) @0x00007f35f484c5d0)

asysimg> 
ufechner7 commented 1 year ago

Please add that @show line into your plot function

I did:

function plot(x, y; keywords...)
    p = figure(; sizing_mode="fixed", width=1200, height=700) # stretch_both
    @show Bokeh.SETTINGS.display
    Bokeh.plot!(p, Bokeh.Line; x=x, y=y, color="blue", line_width=2, keywords...)
    display(p)            
end

I does not change the result:

asysimg> include("src/plot.jl")
Bokeh.SETTINGS.display = BokehBlink.BlinkDisplayBackend()
Figure:
  below = [
    LinearAxis: (blank)
  ]
...
cjdoris commented 1 year ago

OK we're getting closer, the backend is set but it's still displaying the plot as plain text, which must mean the displays are incorrect. Please try again with @show map(typeof, Base.Multimedia.displays) in the plot function just after the other @show.

cjdoris commented 1 year ago

(Adding the Blink package was just for debugging purposes, but you can ignore that now.)

ufechner7 commented 1 year ago
asysimg> @time include("src/plot.jl")
Bokeh.SETTINGS.display = BokehBlink.BlinkDisplayBackend()
map(typeof, Base.Multimedia.displays) = DataType[TextDisplay, Bokeh.BokehDisplay, REPL.REPLDisplay{REPL.LineEditREPL}]
Figure:
  below = [
    LinearAxis: (blank)
  ]
  center = [
cjdoris commented 1 year ago

Ok so the issue is that the Bokeh display is lower down the stack than the REPL display, so plots are shown in the REPL.

I'm guessing this happens because PackageCompiler is storing the display stack after all the packages are loaded, and this already includes the Bokeh one, so it doesn't get added again when the package is actually loaded. I think I know how to fix it.

ufechner7 commented 1 year ago

Thanks for investigating! Looking forward for your fix.

cjdoris commented 1 year ago

I've just released the fix in v0.4.2. Let me know if it works for you now.

ufechner7 commented 1 year ago

Fixed by f6acf4074e4fae2621b3847796b467f949f1ba7f

Thanks a lot! TTFP now 7.4s with system image compared to 15s without.