JuliaGizmos / Interact.jl

Interactive widgets to play with your Julia code
Other
520 stars 75 forks source link

Interaction with fps from Reactive.jl #346

Closed stakaz closed 4 years ago

stakaz commented 4 years ago

Hello, I am trying to do an animation of a simulation process and would like to have a time signal which updates the plot (beside other sliders). I am trying to reproduce examples from https://github.com/JuliaGizmos/Interact.jl/issues/36 but timestamp does not work anymore and I cannot figure out how to combine the fps from Reactive.jl and make it a trigger for the Widget.

Would be glad to see some hints.

Here is the code which does not work:

using Blink
using Compose, Reactive, Interact
anim = @manipulate for x=fps(10.0), color=["tomato", "bisque"], gravity=0:.1:2
    compose(context(0.5, 1-abs(sin(x[1]*gravity)), 0.1, 0.1), fill(color), circle())
end 

w = Window(async = false)
wdg = Widget(["anim" => anim])
body!(w, wdg);

I need the Blink package because I am using julia from within VS code and want a separate window with the animation.

Thanks.

stakaz commented 4 years ago

I found this notebook which can do what I want: https://github.com/JuliaGizmos/Interact.jl/blob/master/doc/notebooks/04-Animations.ipynb

This is the "nearly" working example.

using Blink
using Interact
using Reactive
using GR
GR.inline()

lhs = slider(1:0.1:10) |> onchange

Λ = rand(Int8[-1,1], 10, 10)

timer = Observable(0.0)
t = @async while true
    sleep(0.1)
    timer[] += 0.1
end

function test_plot(t, Λ, args...)
    for i ∈ eachindex(Λ)
        Λ[i] = rand(Int8[-1,1])
    end
    heatmap(Λ .* t)
end

result = map(test_plot, lhs, Λ, timer)

widget = vbox(lhs, result)

window = Window()
body!(window, widget)

However, after the code is run for the first time there is the async job which never ends. Would it be possible to stop it once the Blink window is closed?

This is the error I get for the following code after I close the Blink window.

Info: Connection is not open.
└   connection = Blink.AtomShell.WebIOBlinkComm(Window(1, Electron(Process(`/home/gluon/.julia/packages/Blink/AO8uN/deps/atom/electron /home/gluon/.julia/packages/Blink/AO8uN/src/AtomShell/main.js port 3528`, ProcessRunning), Sockets.TCPSocket(RawFD(0x00000023) active, 0 bytes waiting), Dict{String,Any}("callback"=>##1#2())), Page(1, WebSocket(server, CLOSED), Dict{String,Any}("webio"=>##26#27{WebIOBlinkComm}(WebIOBlinkComm(#= circular reference @-5 =#)),"callback"=>##1#2()), Distributed.Future(1, 1, 1, Some(true))), Task (done) @0x00007ff88ea7a710))
twavv commented 4 years ago

The latter (connection closed warning) is an issue with WebIO.

If you'd be willing to open an issue there, I'd be much obliged.