Makie plot not updating on key press

I am trying to make a simple plot updating on a keypress.
I get the “step” to update when I press the keys, but the plot stays the same. I can’t seem to find any examples of such a case.
It is probably something simple, but I can’t figure it out. Can anyone point me in the right direction?

using GLMakie

fig = Figure(resolution = (1920,1080));
ax = fig[1,1] = Axis(fig);
r = rand(200);

step = Node(1:100)

function step_back()
    global step.val = 10:110
end

function step_forw()
    global step.val = 5:105
end

on(events(fig).keyboardbutton) do event
    if event.action in (Keyboard.press, Keyboard.repeat)
        event.key == Keyboard.left   && step_back()
        event.key == Keyboard.right  && step_forw()
    end
    # Let the event reach other listeners
    return Consume(true)
end

lines!(@lift(r[$step,1]));
display(fig);

node.val = ... updates the value the node holds rather than triggering it. You should be using node[] = .... (Btw Consume(true) is blocking, so the comment there is wrong.)

2 Likes

Thank you! This works like a charm.
I suspected I was missing a minor detail (square brackets are a surprise for me, but I am super fresh with Julia).

As for the comment, it was copied with the code from somewhere in the Makie docs.
I’ll probably go ask on github if they could sort out the docs and create a minimal example that will help people in the future.