cjdoris / Bokeh.jl

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

Exporting to HTML not including bokeh.js #12

Closed astrobc1 closed 2 years ago

astrobc1 commented 2 years ago

Exporting a figure to HTML doesn't seem to include the bokeh.js link. Maybe Im' using the exporting functions incorrectly? Steps to reproduce:

using Bokeh

n = 2_000
z = rand(1:3, n)
x = randn(n) .+ [-2, 0, 2][z]
y = randn(n) .+ [-1, 3, -1][z]
color = Bokeh.PALETTES["Julia3"][z]
p = figure(title="Julia Logo")
plot!(p, Scatter; x, y, color, alpha=0.4, size=10)

doc = Bokeh.Document(p)
dochtml = Bokeh.doc_standalone_html(doc)
open("myfig.html", "w") do io
    write(io, dochtml)
end

Opening the generated myfig.html in the browser results in an empty window because it cannot find Bokeh.

One can fix this by manually injecting the line:

<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.1.min.js"></script>

into the head of the dochtml variable.

cjdoris commented 2 years ago

Oh I forgot to say you need to pass the argument bundle=Bokeh.bundle(), which tells it what JavaScript to load.

These are not API functions, so might change in the future. I need to think about adding an API for saving plots.

astrobc1 commented 2 years ago

That does the trick, thanks!