Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observable plotted dataframe cann't be updated from task #348

Closed
olegshtch opened this issue Jan 22, 2020 · 1 comment
Closed

Observable plotted dataframe cann't be updated from task #348

olegshtch opened this issue Jan 22, 2020 · 1 comment

Comments

@olegshtch
Copy link

I'm trying to update dataframe from background task

using DataFrames, Observables, Interact, Mux, Plots, WebIO

obs = Observables.Observable{DataFrame}(DataFrames.DataFrame(x = 2:3, y = 1:2))
on(obs) do o
	println("On get data")
end

schedule(
	Task(
        	function ()
			println("Waiting for data")
			sleep(60)
	   	        println("Ready!")
			obs[] = DataFrames.DataFrame(x = 2:4, y = 1:3)
		end
	)
)
println("Launched getting data")
function createLayout(req)
	println(req)

	plt = Interact.@map plot((&obs).x ,(&obs).y, label="Model output")
	wdg = Widget(["df" => obs])
	@layout! wdg vbox(plt)
end

function serveLayout(port::Int)
	try
		fetch(WebIO.webio_serve(Mux.page("/", createLayout), port))
	catch e
		if isa(e, IOError)
			# sleep and then try again
			sleep(0.1)
			serveLayout(port)
		else
			throw(e)
		end
	end
end
println("Starting server")
serveLayout(8080)

If I open page before Ready! I will see plot 2:3, 1:2 and when background task finishes I get error:

$ julia 1.jl 
Launched getting data
Starting server
Waiting for data
Dict{Any,Any}(:query => "",:method => "GET",:params => Dict{Any,Any}(),:path => SubString{String}[],:cookies => HTTP.Cookies.Cookie[],:uri => HTTP.URI("/"),:data => UInt8[],:headers => Pair{SubString{String},SubString{String}}["Host" => "localhost:8080", "User-Agent" => "...", "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language" => "ru,en-US;q=0.7,en;q=0.3", "Accept-Encoding" => "gzip, deflate", "Connection" => "keep-alive", "Upgrade-Insecure-Requests" => "1"])
Ready!
On get data
MethodError: no method matching (::var"#7#9")(::DataFrame)
The applicable method may be too new: running in world age 26857, while current world is 26861.
Closest candidates are:
  #7(::Any) at none:0 (method too new to be called from this world context.)
Stacktrace:
 [1] (::Observables.var"#16#17"{var"#7#9",Observable{Any}})(::DataFrame) at /home/olegshtch/.julia/packages/Observables/qCJWB/src/Observables.jl:152
 [2] (::Observables.var"#g#15"{Observables.var"#16#17"{var"#7#9",Observable{Any}},Tuple{Observable{DataFrame}}})(::DataFrame) at /home/olegshtch/.julia/packages/Observables/qCJWB/src/Observables.jl:136
 [3] #setindex!#1(::Observables.var"#2#4", ::typeof(setindex!), ::Observable{DataFrame}, ::DataFrame) at /home/olegshtch/.julia/packages/Observables/qCJWB/src/Observables.jl:87
 [4] setindex!(::Observable{DataFrame}, ::DataFrame) at /home/olegshtch/.julia/packages/Observables/qCJWB/src/Observables.jl:83
 [5] (::var"#5#6")() at /home/olegshtch/julia/1.jl:14

If I open page after Ready! I get plot 2:4, 1:3 without errors.

I've tried to replace

obs[] = DataFrames.DataFrame(x = 2:4, y = 1:3)

with

invokelatest(setindex!, obs, DataFrames.DataFrame(x = 2:4, y = 1:3))

but in this case listeners aren't called and plot doesn't changed.

Julia 1.3.1

  [a93c6f00] DataFrames v0.20.0
  [c601a237] Interact v0.10.3
  [a975b10e] Mux v0.7.1
  [510215fc] Observables v0.2.3
  [91a5bcdd] Plots v0.28.4
  [0f1e0344] WebIO v0.8.13
@olegshtch
Copy link
Author

Looks like invokelatest proveded here from other module. It works if I use Base.invokelatest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant