Pluto.jl · Snapshot.jl · WasmTarget.jl · Native Therapy Components

Interactive Notebooks as Components

Many Julia workflows begin in a Pluto.jl notebook. With Snapshot.jl, you can compile those reactive notebooks to WasmGC and embed them directly inside any Therapy.jl route alongside @island controls and WasmMakie plots. No iframes, no running Julia server.

Interactive 3D WasmMakie Axis3 wave interference surface and Lorenz strange attractor compiled from Pluto to WebAssembly, complete with a scoped sticky PlutoUI TableOfContents running inside Therapy's page shell.

Interactive 3D Surfaces & Chaos in WebAssembly

Every figure in this notebook is a real WasmMakie.Axis3 scene compiled from Julia to WebAssembly and rasterized with a pure-Julia z-buffered Blinn-Phong triangle shader directly onto an HTML <canvas> — no Julia server, no Three.js, and no WebGL.

Drag any slider below to orbit the 3D camera, reshape the wave interference field, or sweep the Rayleigh parameter of the Lorenz attractor in real time.

1. 3D Wave Interference Surface

We evaluate the radially damped interference field

$$z(x, y) = \frac{\sin(\omega r)}{r}, \qquad r = \sqrt{x^2 + y^2}$$

on a $25 \times 25$ grid and shade every quad with WasmMakie.surface! plus an optional WasmMakie.wireframe! mesh and Colorbar.

Camera azimuth (deg) = 230

Camera elevation (deg) = 25

Wave frequency $\omega$ = 1.0

Colormap (1: viridis, 2: plasma, 3: inferno, 4: coolwarm) = 1

Overlay wireframe =

2. The Lorenz Strange Attractor

The classic atmospheric convection system

$$\dot{x} = \sigma (y - x), \qquad \dot{y} = x (\rho - z) - y, \qquad \dot{z} = x y - \beta z$$

with $\sigma = 10$ and $\beta = 8/3$ transitions from decaying spirals ($\rho < 24.74$) to the iconic chaotic butterfly ($\rho = 28$). Below, WebAssembly integrates 1,400 time steps on every slider event and shades the 3D trajectory by instantaneous speed $\|v\|$.

Lorenz azimuth (deg) = 225

Lorenz elevation (deg) = 20

Rayleigh number $\rho$ = 28

3. Dynamical Regime Summary

For $\rho < 24.74$, trajectories spiral inward toward two symmetric fixed points at $(\pm\sqrt{\beta(\rho - 1)},\, \pm\sqrt{\beta(\rho - 1)},\, \rho - 1)$. Above the critical subcritical Hopf threshold $\rho_H \approx 24.74$, both equilibria lose stability and the flow settles onto the iconic two-lobed strange attractor.

Both 3D scenes above run 100% locally in your browser: every slider event invokes a standalone Julia WasmGC module compiled by WasmTarget.jl and rasterized through WasmMakie.Axis3.

using PlutoUI, WasmMakie
_wave_cmap_spec (generic function with 1 method)
function _wave_cmap_spec(idx::Int64)::WasmMakie.ColormapSpec
    if idx == Int64(2)
        return WasmMakie.to_colormap_spec(:plasma)
    elseif idx == Int64(3)
        return WasmMakie.to_colormap_spec(:inferno)
    elseif idx == Int64(4)
        return WasmMakie.to_colormap_spec(:coolwarm)
    end
    return WasmMakie.to_colormap_spec(:viridis)
end
build_wave_surface (generic function with 1 method)
function build_wave_surface(az_deg::Int64, el_deg::Int64, freq::Float64, cmap_idx::Int64, show_wire::Bool)
    az = Float64(az_deg) * 0.017453292519943295
    el = Float64(el_deg) * 0.017453292519943295
    cmap = _wave_cmap_spec(cmap_idx)

    fig = WasmMakie.Figure(size = (760.0, 440.0))
    ax = WasmMakie.Axis3(
        fig[1, 1];
        title = "3D Wave Interference Surface",
        xlabel = "x",
        ylabel = "y",
        zlabel = "sinc(w r)",
        azimuth = az,
        elevation = el,
        perspectiveness = 0.25,
    )

    nx = Int64(25)
    ny = Int64(25)
    xs = Vector{Float64}(undef, nx)
    ys = Vector{Float64}(undef, ny)
    i = Int64(1)
    while i <= nx
        xs[i] = -6.0 + 12.0 * Float64(i - Int64(1)) / Float64(nx - Int64(1))
        i = i + Int64(1)
    end
    j = Int64(1)
    while j <= ny
        ys[j] = -6.0 + 12.0 * Float64(j - Int64(1)) / Float64(ny - Int64(1))
        j = j + Int64(1)
    end

    zs = Vector{Float64}(undef, nx * ny)
    j = Int64(1)
    while j <= ny
        yj = ys[j]
        i = Int64(1)
        while i <= nx
            xi = xs[i]
            r = sqrt(xi * xi + yj * yj)
            wr = freq * r
            zs[i + (j - Int64(1)) * nx] = wr == 0.0 ? 1.0 : sin(wr) / wr
            i = i + Int64(1)
        end
        j = j + Int64(1)
    end

    sf = WasmMakie.surface!(ax, xs, ys, zs, nx, ny; colormap = cmap)
    if show_wire
        WasmMakie.wireframe!(ax, xs, ys, zs, nx, ny; color = (0.0, 0.0, 0.0, 0.22), linewidth = 0.6)
    end
    WasmMakie.Colorbar(fig[1, 2], sf; label = "Amplitude")
    return fig
end
build_lorenz_attractor (generic function with 1 method)
function build_lorenz_attractor(az_deg::Int64, el_deg::Int64, rho_i::Int64)
    az = Float64(az_deg) * 0.017453292519943295
    el = Float64(el_deg) * 0.017453292519943295
    rho = Float64(rho_i)
    sigma = 10.0
    beta = 8.0 / 3.0
    dt = 0.008

    fig = WasmMakie.Figure(size = (760.0, 440.0))
    ax = WasmMakie.Axis3(
        fig[1, 1];
        title = "Lorenz Strange Attractor",
        xlabel = "x",
        ylabel = "y",
        zlabel = "z",
        azimuth = az,
        elevation = el,
        perspectiveness = 0.25,
    )

    n = Int64(1400)
    xs = Vector{Float64}(undef, n)
    ys = Vector{Float64}(undef, n)
    zs = Vector{Float64}(undef, n)
    cs = Vector{Float64}(undef, n)
    x = 1.0
    y = 1.0
    z = 1.0
    i = Int64(1)
    while i <= n
        xs[i] = x
        ys[i] = y
        zs[i] = z
        dx = sigma * (y - x)
        dy = x * (rho - z) - y
        dz = x * y - beta * z
        cs[i] = sqrt(dx * dx + dy * dy + dz * dz)
        x = x + dt * dx
        y = y + dt * dy
        z = z + dt * dz
        i = i + Int64(1)
    end

    ln = WasmMakie.lines!(ax, xs, ys, zs; color = cs, colormap = :plasma, linewidth = 1.7)
    WasmMakie.scatter!(
        ax,
        Float64[xs[1], xs[n]],
        Float64[ys[1], ys[n]],
        Float64[zs[1], zs[n]];
        color = Float64[cs[1], cs[n]],
        colormap = :plasma,
        markersize = 10.0,
        strokecolor = :black,
        strokewidth = 1.0,
    )
    WasmMakie.Colorbar(fig[1, 2], ln; label = "Speed ||v||")
    return fig
end

Tip: toggle light and dark mode in the top bar. Because the notebook mounts natively into Therapy's DOM instead of an iframe, its CSS tokens and SVG diagrams reskin with the page, and switching notebook tabs above runs through Therapy's View Transitions router.

Built for Scientific Julia Workflows

Explore data and models in Pluto, then publish them directly inside a real web application or documentation portal without rewriting your analysis in JavaScript.

One Component Tree

Compose SnapshotNotebook right next to Therapy navigation, authentication, @island forms, and Markdown prose. Shared CSS tokens keep typography and dark mode aligned automatically.

Zero-Server Interactivity

Pluto @bind sliders and inputs drive compiled Julia WasmGC modules directly in the reader's browser. Host on GitHub Pages, Cloudflare, or any static CDN with instant cold starts.

SPA View Transitions

Therapy's client router disposes the previous notebook's WasmGC runtime on therapy:router:before-swap and boots the next notebook cleanly during soft page transitions.

Embed in 3 Steps

Export your Pluto notebook with fragment = true, mount the output directory via staticfiles, and render SnapshotNotebook in any route.

using Snapshot
using Therapy

# 1. Export a reactive Pluto notebook as an embeddable HTML fragment + WasmGC islands
Snapshot.export_notebook(
    "notebooks/svd_geometry.jl";
    output_dir = "notebooks-static",
    theme_picker = false,
    fragment = true,
    fragment_dependencies = :host,
    assets_base = "__PI_ASSETS_BASE__",
)

# 2. Mount the exported assets in app.jl
app = App(
    routes_dir = "src/routes",
    components_dir = "src/components",
    title = "Scientific Dashboard",
)
staticfiles(app, joinpath(@__DIR__, "notebooks-static"), "notebooks-static")

# 3. Render the notebook inside any route (src/routes/notebooks/index.jl)
() -> Div(
    H1("Matrix Geometry Lab"),
    SnapshotNotebook(
        joinpath(@__DIR__, "..", "..", "notebooks-static", "svd_geometry.fragment.html");
        assets_base = "/notebooks-static",
    ),
)

Ready for Evolving WasmTarget & Julia WebAssembly

Both Therapy.jl and Snapshot.jl isolate compilation behind a thin Wasm backend adapter (WasmPlatformSpec, compile_island_wasm, and content-addressed on-disk caching). As WasmTarget.jl expands Julia language coverage and as Julia's native WebAssembly BinaryPlatforms support (Julia PR #64675) brings wasm32 JLL binaries and bridge modules, existing Therapy routes and embedded Snapshot notebooks gain broader Julia package support without rewriting your app.