Display Plots.jl plot in Juliabox


I am using Plots.jl with PlotlyJS backend in Juliabox and I find myself in the situation of calling add_plot to add a trace at the time. I then call gui() at the end of the cell to display the plot. The following code used to work until a couple of weeks ago. It now works (in this minimal example) only if I remove gui().
In the code I have, it seems to work with gui only the first time the cell is executed, but not if I re-execute it. pyplot does not seem to show this problem, but pyplot doesn’t have remote interactivity.

using Plots

function add_plot()



I actually have no idea how gui windows are handled in JuliaBox. I would
expect this wouldn’t work… You should just return the plot object to the
jupyter cell.


As in having the plot object as the last line in the cell? What about if the call to plot! is in a function?


Both plot and plot! return a Plot object. Just make that object be
the last thing in the cell.


PyPlot used from Plots does not need this: I can update a plot deep from a function, without returning it and it has not problem displaying the plot. It seems only related to PlotlyJS,


what about using Plotly instead of PlotlyJS here?


Same thing.
But the fix is easy (although not convenient): return the plot as the last statement in the cell, just what Tom said.

function add_plot()

p = plot()


For completeness… since plot! returns a Plot object, your (seemingly unnecessary but presumably as a minimal example) add_plot method will also return a Plot object. So add_plot() can be the last line of your cell.


You are right. In the code, the add_plot returns nothing.