# How to insert an interactive condition inside a Makie recipe?

**URL:** <https://discourse.julialang.org/t/how-to-insert-an-interactive-condition-inside-a-makie-recipe/137482>\
**Category:** Visualization\
**Tags:** makie, interactivity, observables\
**Created:** [June 7, 2026, 11:50am UTC](https://discourse.julialang.org/t/how-to-insert-an-interactive-condition-inside-a-makie-recipe/137482 "2026-06-07T11:50:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [June 7, 2026, 11:50am UTC](https://discourse.julialang.org/t/how-to-insert-an-interactive-condition-inside-a-makie-recipe/137482/1 "2026-06-07T11:50:47Z")

</div>

The following MWE is self-explanatory:

```julia
using GLMakie
import Makie

# define recipe with condition "showlines"
Makie.@recipe(MyPlot, x, y) do scene
  Makie.Attributes(;
    showlines=true
  )
end

# toggle between scatterlines and scatter
function Makie.plot!(plot::MyPlot)
  if plot.showlines[] # this is the root of the issue
    Makie.scatterlines!(plot, plot.x, plot.y)
  else
    Makie.scatter!(plot, plot.x, plot.y)
  end
end

# initialize plot
x = 1:10
y = rand(10)
showlines = Observable(true)
myplot(x, y; showlines)

# doesn't work
showlines[] = false

```

Setting the observable doesn’t trigger changes in the scene, and that is probably because the syntax `plot.showlines[]` is extracting the node value at that point in time (`true`) and the only branch that is registered in the compute graph is the first one.

I tried to wrap the condition with the new compute pipeline, but it gives an error:

```julia
function Makie.plot!(plot::MyPlot)
  Makie.map!(plot, :showlines, :nothing) do showlines
    if showlines
      Makie.scatterlines!(plot, plot.x, plot.y)
    else
      Makie.scatter!(plot, plot.x, plot.y)
    end
  end
end

```

If there is a better idiom that plays well with compute pipelines, I’d be happy to learn.

---

<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 7, 2026, 1:15pm UTC](https://discourse.julialang.org/t/how-to-insert-an-interactive-condition-inside-a-makie-recipe/137482/2 "2026-06-07T13:15:41Z")

</div>

I’d probably do a scatter and then a separate lines whose visible is connected to your showlines. scatterlines is just scatter plus lines anyway so that’d be the same result. In general, plot insertion is not something that is intended to be governed by the compute graph, it’s the attributes of the inserted plots that form the graph.

The exception here is `plotlist!` to which you can pass an observable of specs. You can use this, it’s just a bit less efficient to update because it has to do some diffing on the arguments I think to determine what can stay and what needs to be removed on updates.

I’ve been using plotlist for example to implement annotations, because when you change the annotation object the visuals can change a lot.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [June 7, 2026, 1:45pm UTC](https://discourse.julialang.org/t/how-to-insert-an-interactive-condition-inside-a-makie-recipe/137482/3 "2026-06-07T13:45:53Z")

</div>

The MWE with `scatterlines` vs. `scatter` was just an example. I wonder what the solution would look like with `plotlist!`. I could also consider making `x` and `y` empty if the recipes themselves handled the empty case, but I think it is not a general solution.

Could you please share how the MWE above could be rewritten in terms of `plotlist!`?

---

<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 7, 2026, 3:50pm UTC](https://discourse.julialang.org/t/how-to-insert-an-interactive-condition-inside-a-makie-recipe/137482/4 "2026-06-07T15:50:37Z")

</div>

```julia
using GLMakie
import Makie.SpecApi as S

@recipe LineOrScatter (xs, ys) begin
    show_lines = false
    color = :tomato
end

function Makie.plot!(p::LineOrScatter)
    map!(p.attributes, [:xs, :ys, :show_lines, :color], :plotspecs) do xs, ys, show_lines, color
        if show_lines
            return [S.Lines(xs, ys; color = color, linewidth = 3)]
        else
            return [S.Scatter(xs, ys; color = color, markersize = 12)]
        end
    end
    plotlist!(p, p.plotspecs)
    return p
end

x = range(0, 4pi; length = 60)
y = sin.(x) .+ 0.15 .* randn(length(x))

fig = Figure(size = (700, 500))
ax = Axis(fig[2, 1]; title = "lineorscatter recipe")

p = lineorscatter!(ax, x, y)

btn = Button(fig[1, 1];
    label = lift(b -> b ? "Show as scatter" : "Show as lines", p.show_lines),
    tellwidth = false,
)
on(btn.clicks) do _
    p.show_lines[] = !p.show_lines[]
end

fig

```

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [June 7, 2026, 4:28pm UTC](https://discourse.julialang.org/t/how-to-insert-an-interactive-condition-inside-a-makie-recipe/137482/5 "2026-06-07T16:28:00Z")

</div>

Does the SpecAPI support custom recipes? Suppose I have my own `CustomPlot1` and `CustomPlot2` instead of `S.Scatter` and `S.Lines`. What needs to be done in order to create a plot list with the custom plots?

---

<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 7, 2026, 5:54pm UTC](https://discourse.julialang.org/t/how-to-insert-an-interactive-condition-inside-a-makie-recipe/137482/6 "2026-06-07T17:54:57Z")

</div>

Not sure, did you try? I think Makie has always had a shared namespace for recipes so probably S.CustomThing would work.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [June 7, 2026, 6:04pm UTC](https://discourse.julialang.org/t/how-to-insert-an-interactive-condition-inside-a-makie-recipe/137482/7 "2026-06-07T18:04:27Z")

</div>

Just wanted to double check there is nothing special about the custom recipes in regards to the SpecAPI. I will give it a try, thank you.
