# GLMakie: figure does not change

**URL:** <https://discourse.julialang.org/t/glmakie-figure-does-not-change/94277>\
**Category:** Visualization\
**Tags:** glmakie\
**Created:** [February 8, 2023, 2:21pm UTC](https://discourse.julialang.org/t/glmakie-figure-does-not-change/94277 "2023-02-08T14:21:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [February 8, 2023, 2:21pm UTC](https://discourse.julialang.org/t/glmakie-figure-does-not-change/94277/1 "2023-02-08T14:21:25Z")

</div>

Hi,

I do not manage to make my fig interactive, below a simplified version of my initial script.

Any idea what is missing?

```julia
using GLMakie

x_ = 0:0.01:8π
obs_ = [Observable(0.0) for s in 1:3]
function example_func(_x, _a, _b, _c)
   return _a.val .+ _b.val .* _x.^_c.val 
end

y_ = example_func(x_, obs_...)

fig = Figure()

sg = SliderGrid(fig[1, 2],
    (label = "a", range = 0.1:0.01:3, format = "{:.1f}", startvalue = 1),
    (label = "b", range = 0:0.01:10, format = "{:.1f}", startvalue = 1),
    (label = "c", range = 0:0.01:2, format = "{:0.1f}", startvalue = 1),
    tellheight = false,
)

sliderobservables = [s.value for s in sg.sliders]

for (_i, _oh) in enumerate(obs_)
    connect!(_oh, sliderobservables[_i])
end

ax1 = Axis(fig[1, 1], title = "Test", xlabel = "x", ylabel = "y", )

lines!(ax1, x_, y_, color = :indigo)

display(fig)

```

P.S.:  
A nice collection of interactive plots can be found here:  
[Examples by garrekstemo](https://github.com/garrekstemo/InteractivePlotExamples.jl/tree/main/examples)  
P.P.S.:  
Under Linux below Julia v1.8.3 you might face difficulties to use GLMakie:

> [@OpenGL/GLFW error building GLMakie](https://discourse.julialang.org/t/opengl-glfw-error-building-glmakie/47598/11):
>
> Note that there’s no need to manually preload libstdc++ in Julia 1.8.4+, Julia will automatically use system libstdc++ if more recent than the one it ships.

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [February 8, 2023, 4:42pm UTC](https://discourse.julialang.org/t/glmakie-figure-does-not-change/94277/2 "2023-02-08T16:42:43Z")

</div>

I saw this function `lift()` the concept is strange to me and I wonder if there is something around like a tutorial to understand this concept better.  
I do not know if this is proper coding, but it works a least:

```julia
[...]
for (_i, _oh) in enumerate(obs_)
    connect!(_oh, sliderobservables[_i])
end
# --- new:
y_ = lift(sliderobservables...) do slvalues...
    example_func(x_, obs_...)
end

[...]

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [February 8, 2023, 5:25pm UTC](https://discourse.julialang.org/t/glmakie-figure-does-not-change/94277/3 "2023-02-08T17:25:46Z")

</div>

A good page to look at for the basics would be [https://docs.makie.org/stable/documentation/nodes/index.html](https://docs.makie.org/stable/documentation/nodes/index.html)

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [February 8, 2023, 6:22pm UTC](https://discourse.julialang.org/t/glmakie-figure-does-not-change/94277/4 "2023-02-08T18:22:23Z")

</div>

This is how I would do it (I took the liberty of removing a lot of underscores because they were noisy to me).

```julia
using GLMakie

x = 0:0.01:8π
obs = Observable(zeros(3)) #Make the whole vector observable

#write your function as if it would not receive observables but a regular vector
function func(x, values) 
   return values[1] .+ values[2] .* x .^ values[3] 
end

#this is where the lift will listen to changes in the observable and apply the function
y = @lift func(x, $obs) 

fig = Figure()
ax1 = Axis(fig[1, 1])
lines!(ax1, x, y)

sg = SliderGrid(fig[1, 2],
    (label = "a", range = 0.1:0.01:3, startvalue = 1),
    (label = "b", range = 0:0.01:10, startvalue = 1),
    (label = "c", range = 0:0.01:2, startvalue = 1),
    tellheight = false,
)

sliderobservables = [s.value for s in sg.sliders]

#Here I connect each slider to the value inside obs and I use notify to trigger "lift" you can simplify it using map or a comprehension but I do it explicitly for clarity
on(sliderobservables[1]) do sl
        obs[][1] = sl[]
        notify(obs)
end

on(sliderobservables[2]) do sl
       obs[][2] = sl[]
       notify(obs)
end

on(sliderobservables[3]) do sl
       obs[][3] = sl[]
       notify(obs)
end

display(fig) #running in the REPL this line is not needed, but let's leave it for completeness

```

---

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [February 8, 2023, 8:13pm UTC](https://discourse.julialang.org/t/glmakie-figure-does-not-change/94277/5 "2023-02-08T20:13:30Z")

</div>

Thanks a lot!!! 🙂  
Step by step I become more familiar with the concept of `Observable` structures.
