Toggle indefinite loop in Pluto Notebook

I knew that I could use observables from Makie to update plots without redrawing them. But I just discovered that when using WGLMakie, this also works in pluto notebooks. Sweet!

So I want to use this functionality to plot some sensor-reading in real-time. Ideally, I would love to be able to use a PlutoUI GUI element to toggle the data-stream on, and to have the plot refresh indefinitely until the GUI element was toggled off. However, once I start a while my_toggle_value loop in one cell, it looks like I am unable to update my_toggle_value until it finnishes, which is never when it is set to true. So I am unable to update variables during the loop, which means that I am unable to break out of it.

I also gave @label and @goto a shot, and I was able to hack together something that is really close to what I want. The only issue is that I need to uncheck the box, AND interrupt the cell. Also, cell interruption feels somewhat hacky, and there might be an end-user involved, so things should look and feel propper.

Is it technically possible to update a variable outside a running loop in Pluto? If not, are there better ways to achieve what I want than the hacky example above?

Maybe the clock function in plutoui could be useful? On the phone so haven’t tried it out.

Edit:
Tried it out and it works, you can decide if you feel it is less hacky.

1 Like

That works just about perfect, thanks! The refresh rate does seem to be significantly lower than my hacy method, but overall it is very worth it. The update rate does not change if I make the clock increment any lower than 1e-2.