SimonDanisch / Bonito.jl

Serving JS to the browser
MIT License
204 stars 29 forks source link

WGLMakie plot stays blank when served over local network #217

Closed valegnr closed 5 months ago

valegnr commented 5 months ago

First of all thanks for your great work! Unfortunately i experience the following Problem: I am serving a Bonito App in my local network. If i access the page with the machine that is running the server, then everything works fine. But if i access the page with a different machine, then everything is displayed except the WGLMakie Figure. I adapted the plotting example to show that other plots work.

using Bonito
using WGLMakie
import WGLMakie as W
import Gadfly as G
import PlotlyLight as PL

function makie_plot()
    N = 10
    function xy_data(x, y)
        r = sqrt(x^2 + y^2)
        r == 0.0 ? 1.0f0 : (sin(r) / r)
    end
    l = range(-10, stop=10, length=N)
    z = Float32[xy_data(x, y) for x in l, y in l]
    W.surface(
        -1 .. 1, -1 .. 1, z,
        colormap=:Spectral,
        figure=(; size=(300, 300))
    )
end

app = App() do session::Session
    p = PL.Plot(
        x=1:20, y=cumsum(randn(20)), type="scatter", mode="lines+markers";
        layout=PL.Config(margin=PL.Config(l=20, r=20, t=20, b=20))
    )
    G.set_default_plot_size(300G.px, 300G.px)
    gp = G.plot([sin, cos], 0, 2pi)
    # The plots already leave lots of white space
    PCard(p) = Card(p, padding="0px", margin="0px")
    return Grid(
        PCard(gp),
        PCard(p),
        PCard(makie_plot());
        columns="repeat(auto-fit, minmax(300px, 1fr))", justify_items="center")
end;

port = 8081
url = "0.0.0.0"
server = Bonito.Server(app, url, port)
wait(server)
# command to run is: julia --project --threads 4 script.jl

Also here is a Screenshot that shows the missing WGLMakie plot:

servedPage

I am on Julia version 1.10.2 and run that script from the commandline with: julia --project --threads 4 .\serveTest.jl I am thankful for any help!

SimonDanisch commented 5 months ago

You need to set proxy_url: Bonito.Server(my_app, "0.0.0.0", port, proxy_url="$(local_ip):$(port)")

valegnr commented 5 months ago

thanks a lot! I needed to add http:// as well to the proxy url.
So: Bonito.Server(my_app, "0.0.0.0", port, proxy_url="http://$(local_ip):$(port)") made it work