Updating embedded plot from JavaScript

I created a bokeh plot in Python (annular_wedge), gave it a name, and exported it to json, as I found information in other posts:

plot = figure(..., name='my_plot')
data = json.dumps(json_item(plot))

and embedded it in JavaScript with

Bokeh.embed.embed_item(data, "divId")

and that works fine. I would now like to update that plot from JavaScript, possibly data and some colors. I tried exploring in the browser:

Bokeh.index.query_one((view) => view.model.name == "my_plot")

which has plenty of stuff but couldn’t find a way to do it. Is there a way to access the data and some properties?
Thanks!

It would be helpful if you showed some part of what is returned so that we can ensure we are on the same page going in. I have to assume a plot object was returned, and in that case, the plot has a renderers property that contains all the glyph renderers. Each glyph renderer in turn has a data source property with the ColumnDataSource for that renderer. That CDS is what you could potentially update.

In general, the best way to obtain help is to provide a complete Minimal Reproducible Example of th code that you have tried. That reduces speculation and allows for direct experimentation and generally will get you better answers, faster.

Thanks Bryan! I’ll try to make a MRE.

I have explored the JS side a bit and now it is much more clear how everything works and I was able to do most of the things I wanted. Thanks Bryan for the input. I needed to get the model as

Bokeh.index.query_one((view) => view.model.name == "fig").model

in the MRE below:

from bokeh.plotting import figure, show

p = figure(name='fig')

p.line(x=[1, 2, 3], y=[1, 2, 3], color='red', legend_label='y1')
p.line(x=[1, 2, 3], y=[2, 3, 4], color='blue', legend_label='y2')

show(p)

One thing I couldn’t change was the legend glyphs, but it seems it needs to follow the renderer’s glyph, so that’s fine. I looked at the legend here:

Bokeh.index.query_one((view) => view.model.name == "fig").model.center[2]