Interactive Plot with MakieLayout

I have been searching for a clear guide or example to making a simple plot + slider gui with MakieLayout. I see how to add sliders in the Makie documentation but not how to make them useful. There are some examples with Makie sliders in the gallery, but these are not clear to me how they work based on the documentation, and it seems to me that the basic Makie sliders are different in behavior from the MakieLayout LSliders as well.

Below is a dummy plot example; what do I have to do to make the slider control the amp variable?

using GLMakie
using AbstractPlotting
using AbstractPlotting.MakieLayout

x = (0:0.01:4) .* π
scene, layout = layoutscene(resolution = (1200, 900))
ax = layout[1, 1] = LAxis(scene)
line1 = lines!(ax, x, 10 * sin.(x))

sl = layout[2, 1] = LSlider(scene, range = 0:0.01:10, startvalue = 3)
amp = sl.value[] # I know this is wrong because amp does not update after assignment

line2 = lines!(ax, x, amp * sin.(x), color=:red) # How to make this line interactive?

scene

1 Like

Perhaps something like this would work:

y = lift(s1.value) do v
   v*sin.(x)
end
line2 = lines!(ax, x, y, color=:red)

Here, lift is basically like map for an observable, meaning the block will trigger every time the s1.value updates, and re-create the y-array with the correct value.

Excellent, thank you!