Genie Discord forum
![Author Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
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
@genietools
# 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,
mode="lines")
return trace
end
# 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",
xaxis=PlotlyBase.attr(
title=raw"\theta",
showgrid=true
),
yaxis=PlotlyBase.attr(
title=raw"\sin(\theta)",
range=[-11, 11],
showgrid=true
)
)
@onchange button1 begin
traces = [update_plot(A, ω, ϕ)]
end
end
# register a new route and the page that will be
# loaded on access
@page("/", "app.jl.html")
end
What do I need to correct or add to the code? Thank you in advance.
![Author Avatar](https://cdn.discordapp.com/avatars/743412727464067154/bc30abeb49653e9978c0f7c90f4486a8.png?size=512)
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
https://plotly.com/julia/LaTeX/
This is the code with the things I tried:
module App
using GenieFramework
using PlotlyJS
using LaTeXStrings
using StippleLatex
@genietools
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>"))
end
ui() = ["Only this works: ", span(latex"\alpha"), plotly(:plot)]
@page("/", ui)
end
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 Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
In order to activate LaTeX syntax in plotly figures, it is sufficient to add
mathjax() = [script(async = "", type = "text/javascript", src = "https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-MML-AM_CHTML")]
@deps mathjax
![Author Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
Then you can use name = L"a^2+b^2=c^2"
for your legend
![Author Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
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 Avatar](https://cdn.discordapp.com/avatars/960642755799941150/8454099b3f43462890d75bc9c4cd572d.png?size=512)
plot_layout = PlotlyBase.Layout(title=L"\text{This is }\pi r^2")