# Dynamical label text using @lift (makie)

**URL:** <https://discourse.julialang.org/t/dynamical-label-text-using-lift-makie/87117>\
**Category:** General Usage\
**Created:** [September 12, 2022, 7:54am UTC](https://discourse.julialang.org/t/dynamical-label-text-using-lift-makie/87117 "2022-09-12T07:54:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iker96](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@Iker96](https://discourse.julialang.org/u/Iker96)\
**Post date:** [September 12, 2022, 7:54am UTC](https://discourse.julialang.org/t/dynamical-label-text-using-lift-makie/87117/1 "2022-09-12T07:54:40Z")

</div>

Hi, I am trying to simulate a football game with Makie. Thereby the score and the time are updated in each step of the animstep!() function. I do not get an error message, but neither the time nor the result is updated.

```julia
using GLMakie
using Makie
using FileIO
using CairoMakie

t = Observable("0:00")
goals_x = Observable(0)
goals_y = Observable(0)

times = game_time() #array with strings from "0:00" to "90:00"

fig = Figure(resolution=(600, 600),backgroundcolor = "skyblue")
axes = Axis(fig[1,0], aspect = DataAspect(), yreversed = false, title = "Ecuador")
    hidedecorations!(axes)
    hidespines!(axes)
    tightlimits!.(axes)

axes1 = Axis(fig[1,3], aspect = DataAspect(), yreversed = false, title = "Qatar")
    hidedecorations!(axes1)
    hidespines!(axes1)
    tightlimits!.(axes1)

text = @lift("$($t)")
result = @lift("$($goals_x):$(($goals_y))")

image!(axes, img)
image!(axes1, img1)

Label(fig[1, :], result, textsize = 50)
Label(fig[0, :], text, textsize = 20)

display(fig)

for i in 1:(90*60 + 1)
    animstep!("A1","A2",teams,i,t,goals_x,goals_y,times)
    #sleep(0.001)
end

```

The animstep!() is defined as follows:

```julia
function animstep!(x,y,teams,i,t,goals_x,goals_y,times)
    t[] = times[i]
    goals_x[] += game_step("A1","A2",teams,i)[1]
    goals_y[] += game_step("A1","A2",teams,i)[2]
end

```

About a tip or any form of help I would be very grateful 🙂

---

<div class="post-metadata">

**Author:** ![RayleighLord](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayleighlord/32/33592_2.png) [@RayleighLord](https://discourse.julialang.org/u/RayleighLord)\
**Post date:** [September 12, 2022, 8:44am UTC](https://discourse.julialang.org/t/dynamical-label-text-using-lift-makie/87117/2 "2022-09-12T08:44:16Z")

</div>

I was able to update a Label successfully using this small example

```julia
using GLMakie

time = Observable(0.0)
dt = 0.1

text = @lift("time = $($time)")

fig = Figure()
ax = Axis(fig[1, 1])
Label(fig[1, 1], text)

step!() = time[] += dt

for i in 1:100
    step!()
    sleep(0.01)
end

```

Try to reduce your code to a MWE (Minimum Working Example) so I could take a look and run it to see what is failing if you still have not managed to solve the issue.

---

<div class="post-metadata">

**Author:** ![Iker96](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@Iker96](https://discourse.julialang.org/u/Iker96)\
**Post date:** [September 12, 2022, 8:59am UTC](https://discourse.julialang.org/t/dynamical-label-text-using-lift-makie/87117/3 "2022-09-12T08:59:55Z")

</div>

Thanks for your answer! I think your code is a good example of a MWE for my code. One difference is that I still have display(fig) after the line “Label(fig[1, 1], text)”. If I don’t add display(fig), then when I run your code in my notebook, no figure is output. Maybe this is the problem ?

I used this example to create my code: [Making animated and interactive scientific visualizations in Makie.jl · GitHub](https://gist.github.com/Datseris/4b9d25a3ddb3936d3b83d3037f8188dd).

---

<div class="post-metadata">

**Author:** ![RayleighLord](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayleighlord/32/33592_2.png) [@RayleighLord](https://discourse.julialang.org/u/RayleighLord)\
**Post date:** [September 12, 2022, 10:29am UTC](https://discourse.julialang.org/t/dynamical-label-text-using-lift-makie/87117/4 "2022-09-12T10:29:41Z")

</div>

You do need `display(fig)` if you are working on a Jupyter Notebook, for example.

But, even when using a Jupyter notebook, executing the following code inside a single cell works for me.

```julia
using GLMakie

time = Observable(0.0)
dt = 0.1

text = @lift("time = $($time)")

fig = Figure()
ax = Axis(fig[1, 1])
Label(fig[1, 1], text)

step!() = time[] += dt

display(fig)

for i in 1:100
    step!()
    sleep(0.01)
end

```

What are you using to execute your code?

---

<div class="post-metadata">

**Author:** ![Iker96](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@Iker96](https://discourse.julialang.org/u/Iker96)\
**Post date:** [September 13, 2022, 6:02am UTC](https://discourse.julialang.org/t/dynamical-label-text-using-lift-makie/87117/5 "2022-09-13T06:02:28Z")

</div>

Hi, I finally found my error. Apparently the output of my cernel was blocked because the port was unreachable due to the machine’s firewall security. After I changed the port everything works again.

I work with Jupyter Notebook (1.8.0). I had overlooked that in the command prompt the error " zmq message arrived on closed channel" was returned .

Thanks for your help! Without your example of error free code, I would never have found my error.
