# Update text value when changing an Observable in GLMakie

**URL:** https://discourse.julialang.org/t/update-text-value-when-changing-an-observable-in-glmakie/90572
**Category:** Visualization
**Tags:** plotting, glmakie
**Created:** [November 21, 2022, 6:42am UTC](https://discourse.julialang.org/t/update-text-value-when-changing-an-observable-in-glmakie/90572 "2022-11-21T06:42:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![garrek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garrek/32/27937_2.png) [@garrek](https://discourse.julialang.org/u/garrek)
#### Post date: [November 21, 2022, 6:42am UTC](https://discourse.julialang.org/t/update-text-value-when-changing-an-observable-in-glmakie/90572/1 "2022-11-21T06:42:32Z")

</div>

I’m trying to update a text value to reflect a change in one or more `Observable`. I’ve tried to do this a couple of ways.

If the `Observable` is

`obs = Observable(1.0)`

I’ve tried putting it in a `Label`

`Label(fig, "$(obs)")`

using a few different ways of getting the value. If you use `to_value(obs)`, this eliminates the `Observable` reference, I think, so the value will not update again. I’ve also tried to `lift()` the value.

I’ve also tried to put it directly on the plot using `text!()`. There was a time when I got that to work several months ago, but I can’t remember what I did and Makie has changed a lot since then.

I know that `Slider` has a built-in label, but having text that reflects `Observable` changes is more powerful. In the example below, there are two sine wave, and their parameters can change with sliders. I want to calculate the difference in the frequencies of the two sine waves and display it.

Is there a way to do this, or have I just not found it yet?

- [Observables and interactivity reference here](https://docs.makie.org/v0.18.3/documentation/nodes/)
- [SliderGrid reference here](https://docs.makie.org/v0.18.3/examples/blocks/slidergrid/)

 ![Screenshot 2022-11-21 at 15.43.35](https://global.discourse-cdn.com/julialang/original/3X/1/3/13416a434e3690dbbee6043b825f4bbad278b2fa.png)

---

<div class="post-metadata">

### Author: ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)
#### Post date: [November 21, 2022, 10:30am UTC](https://discourse.julialang.org/t/update-text-value-when-changing-an-observable-in-glmakie/90572/2 "2022-11-21T10:30:37Z")

</div>

```julia
using GLMakie
GLMakie.activate!()

f = Figure()

slider1 = Slider(f[1,1], range=0.0:0.1:1.0)
slider2 = Slider(f[2,1], range=0.0:0.1:1.0)

label = lift(slider1.value, slider2.value) do s1, s2
    return "Difference = $(s1 - s2)"
end
Label(f[3,1], label)

display(f)

```

---

<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: [November 21, 2022, 10:38am UTC](https://discourse.julialang.org/t/update-text-value-when-changing-an-observable-in-glmakie/90572/3 "2022-11-21T10:38:22Z")

</div>

> [@garrek](#):
>
> Label(fig, “$(obs)”)

Or going off of this syntax (which doesn’t work because you’re trying to interpolate an Observable into a string) you can do `Label(fig, @lift "$($obs)")`. The first `$` is the normal string interpolation syntax, the second `$` means “use an observable’s value here”.

---

<div class="post-metadata">

### Author: ![garrek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garrek/32/27937_2.png) [@garrek](https://discourse.julialang.org/u/garrek)
#### Post date: [November 21, 2022, 11:59am UTC](https://discourse.julialang.org/t/update-text-value-when-changing-an-observable-in-glmakie/90572/4 "2022-11-21T11:59:38Z")

</div>

Thank you both @fatteneder and @jules.

> [@jules](#):
>
> `Label(fig, @lift "$($obs)")`

This works if you add a couple more parentheses: `Label(fig, @lift("$($obs)"))`.

---

<div class="post-metadata">

### Author: ![garrek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/garrek/32/27937_2.png) [@garrek](https://discourse.julialang.org/u/garrek)
#### Post date: [November 21, 2022, 12:07pm UTC](https://discourse.julialang.org/t/update-text-value-when-changing-an-observable-in-glmakie/90572/5 "2022-11-21T12:07:44Z")

</div>

By the way, I’m working on some[examples of interactivity with GLMakie](https://github.com/garrekstemo/InteractivePlotExamples.jl). There are only a couple right now, but I’ll make a separate post when I have enough that I think they will be more broadly useful.
