From 80c818c7629f468c90cae07908c7e2a95ae81878 Mon Sep 17 00:00:00 2001 From: Joel Mason Date: Wed, 2 Nov 2016 07:38:10 +1100 Subject: [PATCH] Fixes use with Interact in IJulia on page refresh See https://github.com/JuliaLang/Interact.jl/issues/115 for more context --- src/PlotlyJS.jl | 2 +- src/displays/ijulia.jl | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/PlotlyJS.jl b/src/PlotlyJS.jl index 4247d691..9837dc29 100644 --- a/src/PlotlyJS.jl +++ b/src/PlotlyJS.jl @@ -121,7 +121,7 @@ function __init__() end # set up the comms we will use to send js messages to be executed - global const _ijulia_eval_comm = Comm(:plotlyjs_eval) + global const _ijulia_eval_comm = Ref(Comm(:plotlyjs_eval)) global const _ijulia_return_comms = ObjectIdDict() @eval begin diff --git a/src/displays/ijulia.jl b/src/displays/ijulia.jl index 819b9bd1..2ae18d41 100644 --- a/src/displays/ijulia.jl +++ b/src/displays/ijulia.jl @@ -10,7 +10,10 @@ end typealias JupyterPlot SyncPlot{JupyterDisplay} -JupyterDisplay(p::Plot) = JupyterDisplay(p.divid, false, Condition()) +JupyterDisplay(p::Plot) = begin + _ijulia_eval_comm[] = Comm(:plotlyjs_eval) + JupyterDisplay(p.divid, false, Condition()) +end JupyterPlot(p::Plot) = JupyterPlot(p, JupyterDisplay(p)) fork(jp::JupyterPlot) = JupyterPlot(fork(jp.plot)) @@ -71,8 +74,9 @@ end # Helper functions # # ---------------- # -_call_js(jd::JupyterDisplay, code) = - send_comm(_ijulia_eval_comm, Dict("code" => code)) +_call_js(jd::JupyterDisplay, code) = begin + send_comm(_ijulia_eval_comm[], Dict("code" => code)) +end ## API Methods for JupyterDisplay _the_div_js(jd::JupyterDisplay) = "document.getElementById('$(jd.divid)')"