# Update an external Observable in Makie recipe

**URL:** <https://discourse.julialang.org/t/update-an-external-observable-in-makie-recipe/116617>\
**Category:** General Usage\
**Tags:** makie, recipe, observables\
**Created:** [July 4, 2024, 10:15am UTC](https://discourse.julialang.org/t/update-an-external-observable-in-makie-recipe/116617 "2024-07-04T10:15:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NicoD](https://avatars.discourse-cdn.com/v4/letter/n/13edae/32.png) [@NicoD](https://discourse.julialang.org/u/NicoD)\
**Post date:** [July 4, 2024, 10:15am UTC](https://discourse.julialang.org/t/update-an-external-observable-in-makie-recipe/116617/1 "2024-07-04T10:15:01Z")

</div>

In Julia, an observable can be passed as argument to a function, and when the function updates its value, the changes are visible from outside the function (the observable declared outside is updated).

Simple working example:

```julia
obs = Observable(0)
on(obs) do obs
  println("updated")
end
function updateobs(observable::Observable)
  observable[] += 1
end

updateobs(obs) # calls println("updated")

```

However, when the function is from a Makie recipe, the observable seems transformed, and cannot be updated anymore. I even tried to pass it as an attribute, without success. Is it possible to achieve that, or not with the current recipe architecture ? My solution for now is to not use a recipe, and define an independant plotting function, but it would be better to use a recipe.

Simple not working example:

```julia
obs = Observable([1,2,3])
on(obs) do obs
  println("updated")
end

@recipe(TestPlot) do scene
    Attributes(
        color = (:red, 0.8),
    )
end

function Makie.plot!(tp::TestPlot{<:Tuple})
    obs = tp[1]
    # update observable
    obs[] = obs.val .+ 1
    lines!(tp, obs, color = tp.color)
    tp
end

f = Figure()
ax = Axis(f[1,1])
testplot!(ax, obs)
# does not print "updated"

```

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [July 4, 2024, 11:02am UTC](https://discourse.julialang.org/t/update-an-external-observable-in-makie-recipe/116617/2 "2024-07-04T11:02:06Z")

</div>

You are looking at a new observable inside the recipe that is created during the plotting pipeline. Try `plot.args[1]` maybe, but even that might be copied.

---

<div class="post-metadata">

**Author:** ![NicoD](https://avatars.discourse-cdn.com/v4/letter/n/13edae/32.png) [@NicoD](https://discourse.julialang.org/u/NicoD)\
**Post date:** [July 4, 2024, 12:17pm UTC](https://discourse.julialang.org/t/update-an-external-observable-in-makie-recipe/116617/3 "2024-07-04T12:17:35Z")

</div>

Indeed, `tp.args[1]` instead of `tp[1]` is giving the original observable, thanks !
