Hi!
I am trying to embed my makie plots as html files in my github pages website which uses jekyll.
I found this blog post which explains how it can be done: using Julia to do web based interactive plotting | Aaron Trowbridge
I imported the HTML files he generated and they work fine. However I am not able to generate such files myself yet for my own plots, his script throws some errors.
I have the following test code:
using WGLMakie
import WGLMakie as W
using Bonito
WGLMakie.activate!() # Ensure WGLMakie is used
# this is optional and just changes the color theme
set_theme!(theme_dark())
# radial sinc function with scale parameter "a"
radial_sinc(x, y, a) = sinc(a * hypot(x, y))
# domain of surface
xs = LinRange(-5, 5, 150)
ys = LinRange(-5, 5, 150)
# creating the javascript app
app = App() do session::Session
scale_slider = Slider(1:3)
states = map(scale_slider) do a
return [radial_sinc(x, y, a) for x in xs, y in ys]
end
fig, ax, = surface(xs, ys, states, figure=(size=(700, 400),))
scale_value = DOM.div("\\(a = \\)", scale_slider.value)
return Bonito.record_states(
session,
DOM.div(fig, scale_value, scale_slider)
)
end
output_file = "_posts/examples/diffeqviz/sinc_surface.html"
Bonito.export_static(output_file, app)
I noticed that the file created by Aaron has the following structure:
<center>
<div id="347664a4-937a-4c8c-8d0a-0f724a4fca5a" data-jscall-id="40" style="visibility: hidden;">
<div data-jscall-id="20">
<div data-jscall-id="22">
<canvas data-jscall-id="21" tabindex="0"></canvas>
</div>
<div data-jscall-id="19">\(a = \)
<span data-jscall-id="23">1</span>
</div>
<input step="1" max="3" min="1" data-jscall-id="24" value="1" oninput="JSServe.update_obs('16154021666513593650', parseFloat(value))" type="range" />
</div>
<script data-jscall-id="37" type="text/javascript">
window.__define = window.define;
window.__require = window.require;
window.define = undefined;
window.require = undefined;
</script>
<script data-jscall-id="38" type="text/javascript">
window.define = window.__define;
window.require = window.__require;
window.__define = undefined;
window.__require = undefined;
</script>
<script data-jscall-id="39" type="text/javascript">
(()=> {
JSServe.register_sub_session('347664a4-937a-4c8c-8d0a-0f724a4fca5a')
const init_data_b64 = 'H4sIAAAAAAAAA1ydd7j....'
JSServe.init_from_b64(init_data_b64)
if (!true){
JSServe.update_obs('16814681312933192367', true)
}
})()
</script>
</div>
</center>
Is there a way to replicate this in the new version of Bonito?