JuliaPlots / JuliaPlots/PlotlyJS.jl
IJulia comm
- Dominant language
- Julia
- Stars
- 444
- Forks
- 86
- PR merge metrics
- No merged PRs in 30d
Description
We've recently merged in some functionality that let's us have tighter communication with javascript in the notebook. These are the main things that have happened to enable this:
- When we start up in the notebook we now load up a [javascript file](https://github.com/spencerlyon2/PlotlyJS.jl/blob/master/src/displays/ijulia.js) that prepares the javascript console in the browser where the notebook is running to receive messages from PlotlyJS.jl
- On the javascript side, we have implemented two different evaluation targets for a jupyter-plotlyjs.jl comm:
1. [One](https://github.com/spencerlyon2/PlotlyJS.jl/blob/037cf06bfb4fb7cf96498d5ea3d890e003abf84b/src/displays/ijulia.js#L27-L35) that simply sends javascript to be evaluated
2. A [second one](https://github.com/spencerlyon2/PlotlyJS.jl/blob/037cf06bfb4fb7cf96498d5ea3d890e003abf84b/src/displays/ijulia.js#L37-L53) that executes the passed javascript, resolves any promises that were returned when the js was evaluated, and then sends the data back to Julia. (the sending happens [here](https://github.com/spencerlyon2/PlotlyJS.jl/blob/037cf06bfb4fb7cf96498d5ea3d890e003abf84b/src/displays/ijulia.js#L47))
- On the Julia side we now have one comm per JupyterDisplay. Really this means one comm per displayed figure. This comm will allow us to tap into those two targets we defined in the javascript file and send code to the javascript console to be evaluated.
- This is initialized [here](https://github.com/spencerlyon2/PlotlyJS.jl/blob/d64e42ad63c91fa98984c1de972da11f3696ffe8/src/displays/ijulia.jl#L68-L94)
- We then define two julia functions, one for each of the two targets. They are [here](https://github.com/spencerlyon2/PlotlyJS.jl/blob/037cf06bfb4fb7cf96498d5ea3d890e003abf84b/src/displays/ijulia.jl#L110-L116)
Now, what the status?
We have great Julia => javascript communication. This is evident in how well PlotlyJS.jl works inside an `@manipulate` call using Interact.jl.
What isn't working is getting data to go javascript => julia. Because plotly.js is async and uses promises in almost all functions, we need to do things async on the Julia side also.
To make this work, I've added a field `cond::Condition` on JupyterDisplay. This is the `Condition` from Base and it will allow us to [`notify` when data is ready](https://github.com/spencerlyon2/PlotlyJS.jl/blob/037cf06bfb4fb7cf96498d5ea3d890e003abf84b/src/displays/ijulia.jl#L84) and it will allow us to [`wait` until it is ready](https://github.com/spencerlyon2/PlotlyJS.jl/blob/037cf06bfb4fb7cf96498d5ea3d890e003abf84b/src/displays/ijulia.jl#L112).
The issue we're facing now is that the [`on_msg`](https://github.com/spencerlyon2/PlotlyJS.jl/blob/037cf06bfb4fb7cf96498d5ea3d890e003abf84b/src/displays/ijulia.jl#L89) callback we attach to each comm never seems to be called. To verify this I added [these lines](https://github.com/spencerlyon2/PlotlyJS.jl/blob/037cf06bfb4fb7cf96498d5ea3d890e003abf84b/src/displays/ijulia.jl#L75-L77) that simply create a file in the User's home directory when the callback is called. This file never appears.
I've tried a few things and haven't yet figured out what the hang up is. My assumption was that calling `comm.send` in the [javascript](https://github.com/spencerlyon2/PlotlyJS.jl/blob/037cf06bfb4fb7cf96498d5ea3d890e003abf84b/src/displays/ijulia.js#L47) would trigger `comm.on_msg` to be called in the Julia -- but that doesn't seem to happen.
Any ideas for why this is happening would be great.
cc @tbreloff
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.