# Makie @lift for a function with multiple outputs?

**URL:** <https://discourse.julialang.org/t/makie-lift-for-a-function-with-multiple-outputs/62236>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [June 1, 2021, 11:49pm UTC](https://discourse.julialang.org/t/makie-lift-for-a-function-with-multiple-outputs/62236 "2021-06-01T23:49:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Post date:** [June 1, 2021, 11:49pm UTC](https://discourse.julialang.org/t/makie-lift-for-a-function-with-multiple-outputs/62236/1 "2021-06-01T23:49:15Z")

</div>

I’m trying to make a menu in Makie which changes the plot. Basically this:

```julia
using GLMakie

fig = Figure()
menu = Menu(fig, options = [1,2])
fig[1, 1] = vgrid!(
    Label(fig, "Index a", width = nothing),menu;
    tellheight = false, width = 200)

ax = LScene(fig[1, 2])
a = Node{Int}(1)

function my_function(a,x)
    data = [sin.(pi*x), cos.(pi*x)]
    return data[a]
end
xplot = LinRange(-1,1,100)
yplot = @lift my_function($a,xplot) 
plt = scatter!(ax, xplot, yplot)

on(menu.selection) do s
    a[] = s     
end
fig

```

except that my actual `my_function` returns multiple outputs

```julia
function my_function(a,x)
    data = [sin.(pi*x), cos.(pi*x)]
    other_stuff = rand()
    return data[a],other_stuff
end

```

Node and `@lift` don’t seem to work for this setting (I get `ERROR: LoadError: MethodError: no method matching iterate(::Observable{Tuple{Vector{Float64}, Float64}})`). Is there a way around this?

---

<div class="post-metadata">

**Author:** ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Post date:** [June 2, 2021, 2:43am UTC](https://discourse.julialang.org/t/makie-lift-for-a-function-with-multiple-outputs/62236/2 "2021-06-02T02:43:40Z")

</div>

Well, I fixed this by just rewriting the function, but I’m still not sure how to fix this in a less invasive way.

---

<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:** [June 2, 2021, 6:38am UTC](https://discourse.julialang.org/t/makie-lift-for-a-function-with-multiple-outputs/62236/3 "2021-06-02T06:38:19Z")

</div>

> [@jlchan](#):
>
> `yplot = @lift my_function($a,xplot)`

If I understand correctly, just index into the result here.

```julia
yplot = @lift my_function($a,xplot)[1]

```

Also you technically don’t need `a`, you can use the selection observable directly

```julia
yplot = @lift my_function($(menu.selection), xplot)[1]

```

---

<div class="post-metadata">

**Author:** ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Post date:** [June 2, 2021, 1:54pm UTC](https://discourse.julialang.org/t/makie-lift-for-a-function-with-multiple-outputs/62236/4 "2021-06-02T13:54:25Z")

</div>

Thanks! So if I need `other_stuff` as well, I guess I’ll just index into `my_function` again.

And directly using `$(menu.selection)` works, just needed to initialize `menu.selection[] = 1` beforehand.
