PlotlyJS update subplot traces in-place

In PlotlyJS, I can update a trace in-place using react!() as mentioned in the docs:

tr = scatter(;y=rand(5))
p = plot(tr)
tr[:y] .= rand(5)
react!(p,[tr],Layout())

However, I don’t see any information on how to do in-place updating of subplot data. For example:

p = make_subplots(rows=2, cols=1, shared_xaxes=true, vertical_spacing=0.02)
tr1 = scatter(;y=rand(5))
tr2 = scatter(;y=rand(10))
add_trace!(p, tr1, row=1, col=1)
add_trace!(p, tr2,  row=2, col=1)
p

The goal is then to do something like

tr1[:y] .= rand(5)
react!(p,[tr1],row=1,col=1)

but react! doesn’t take row/col keywords. I’d like to avoid redrawing the whole plot.
Any help is greatly appreciated!

The solution I found is to not use the make_subplots() function, and instead use the lower level API mentioned at the bottom of this page: Subplots in Julia

A MWE is then:

tr1 = scatter(;y=rand(5))
tr2 = scatter(;y=rand(10),yaxis="y2")
L1 = Layout(yaxis_domain=[0, 0.5], yaxis2_domain=[0.51, 1], yaxis2_anchor="x2")
p = plot([tr1,tr2],L1)

with the update step

tr2[:y] .= rand(10)
react!(p,[tr1, tr2],L1)
1 Like