Genie Discord forum

Author AvatarCeboc54
11/3/2023, 7:41:54 AM

I tried to use StippleLatex.jl to render the plot axis with LaTeX labels, and I got this error:

┌ Error: 2023-11-02 14:05:34 GET /js/stipplekatex/katex.min.css 404
└ @ Genie.Router ~/.julia/packages/Genie/Ow2eW/src/Router.jl:202

My Julia script looks like:

module App
# set up Genie development environment
using GenieFramework
using Main.Sine
import PlotlyBase, StipplePlotly
using StippleLatex


# add your data analysis code

# x range
const xs = collect(range(-2π, 2π, length=1000))

# function called to update de plot
function update_plot(A, ω, ϕ)
    ys = @. sine(xs, A, ω, ϕ)
    trace = PlotlyBase.scatter(x=xs, y=ys,
    return trace

# Define default values for reactive variables
A_default = 0.0
ω_default = 0.0
ϕ_default = 0.0

# add reactive code to make the UI interactive
@app begin
    # reactive variables are tagged with @in and @out
    @in A = A_default
    @in ω = ω_default
    @in ϕ = ϕ_default
    @in button1 = false
    @out traces = [update_plot(A_default, ω_default, ϕ_default)]
    @out layout = PlotlyBase.Layout(title="Sine function",
        range=[-11, 11],

    @onchange button1 begin
        traces = [update_plot(A, ω, ϕ)]

# register a new route and the page that will be
# loaded on access
@page("/", "app.jl.html")

What do I need to correct or add to the code? Thank you in advance.

Author AvatarPere
11/3/2023, 9:34:23 AM

Using Latex strings in plots is something that needs to be supported by PlotlyJS. Apparently it does, but I couldn't get any of their examples to work

This is the code with the things I tried:

module App
using GenieFramework
using PlotlyJS
using LaTeXStrings
using StippleLatex


trace1 = scatter(; x=1:4, y=[0, 2, 3, 5], fill="tozeroy", name="<span v-katex=\"'\\alpha'\"></span>")
trace2 = scatter(; x=1:4, y=[3, 5, 1, 7], fill="tonexty", name=L"$\theta$")

@app begin
    @out plot = Plot([trace1, trace2], PlotlyJS.Layout(title=L"$aaa$", xaxis_title="<span v-katex= hehehe></span>"))

ui() = ["Only this works: ", span(latex"\alpha"), plotly(:plot)]

@page("/", ui)

only the span(latex"\alpha")worked, and I didn't get any error about missing css files. What package versions are you on? Can you try to update to the latest and see you're still getting the same error?

Author Avatarhhaensel
12/5/2023, 7:06:45 AM

In order to activate LaTeX syntax in plotly figures, it is sufficient to add

mathjax() = [script(async = "", type = "text/javascript", src = "")]
@deps mathjax
Author Avatarhhaensel
12/5/2023, 7:07:27 AM

Then you can use name = L"a^2+b^2=c^2" for your legend

Author Avatarhhaensel
12/5/2023, 7:10:43 AM
plot_data = [scatter(y = collect(1:10), name = L"a^2 + b^2 = c^2"), scatter(y = 2:3, name = L"\omega\theta\phi")]
Author Avatarhhaensel
12/5/2023, 7:11:36 AM
plot_layout = PlotlyBase.Layout(title=L"\text{This is }\pi r^2")