Animation with start and stop control in Plots.jl?

Hello.
I started my experiments on animations using Plots.jl. There is a quite useful webpage: Animations with Plots.jl (juliafordatascience.com)
Using @animate or @gif macros, it’s quite easy to generate animations. However, if I create these animated plots, they just loop indefinitely without stopping. I want to control this behavior by adding “Start” and “Stop” buttons. Is there any simple way to create such control buttons? I guess it’s easier to use Pluto.jl. But I am also interested in doing this under vscode. Thanks a lot for your help!

See here how to get an mp4 instead of a gif file from the animation frames:
https://discourse.julialang.org/t/having-problems-with-creating-animations-with-plots-jl-grbackend-juno/21876/2.

If you just want video controls like play/pause then you can probably display a <video> tag linking to the local video file generated with Plots.jl in the VSCode plot pane and that would work because VSCode is basically a browser.

But as you mentioned Pluto.jl, it sounds like you might be thinking about some kind of simple UI for controlling animations? Another option for that if you want it to work in VSCode is WGLMakie.jl. Here’s a basic animation of a dataset (and this doesn’t just loop but pulls in new data) with a start and stop button as an example, if you’re interested to go down that road.

1 Like

Thanks a lot, @jules. But if possible, I want to stick with Plots.jl. Also, I want to run the animation under Pluto.jl. I found that gif function of Plots.jl has an input argument called loop, which is set to 0 by default. It seems to me that this argument is passed to ffmpeg. According to ffmpeg documentation, the infinite loop should be specified by -stream_loop -1, not -stream_loop 0. But at this point, gif(anim, loop=0) repeats the animation indefinitely. When I call gif(anim, loop=1) instead, it just runs the animation once. But when I click the execution button in Pluto notebook for the second time, it doesn’t run animation unless I change some other parameters…