Back to Bokeh

get a handle to update the shown cell with

examples/output/jupyter/push_notebook/Basic Usage.ipynb

3.10.0.dev41.7 KB
Original Source
python
from bokeh.io import push_notebook, show, output_notebook
from bokeh.layouts import row
from bokeh.plotting import figure
output_notebook()
python
opts = dict(width=250, height=250, min_border=0)
python
p1 = figure(**opts)
r1 = p1.scatter([1,2,3], [4,5,6], size=20)

p2 = figure(**opts)
r2 = p2.scatter([1,2,3], [4,5,6], size=20)

# get a handle to update the shown cell with
t = show(row(p1, p2), notebook_handle=True)
python
# the comms handle repr show what cell it can be used to update
t
python
# this will update the left plot circle color with an explicit handle
r1.glyph.fill_color = "white"
push_notebook(handle=t)
python
# and this will update the right plot circle color because it was in the last shown cell
r2.glyph.fill_color = "pink"
push_notebook()
python
p3 = figure(**opts)
r3 = p3.scatter([1,2,3], [4,5,6], size=20)

# get a handle to update the shown cell with
t2 = show(p3, notebook_handle=True)
python
# show which cell t2 handles
t2
python
# this updates the immediately previous cell with an explicit handle
r3.glyph.fill_color = "orange"
push_notebook(handle=t2)
python
# this updates the left plot at the top with an explicit handle
r1.glyph.fill_color = "orange"
push_notebook(handle=t)
python
# get a handle to update the shown cell with
t3 = show(p2, notebook_handle=True)
python
# this will update the immediately previous plot circle color because it was in the last shown cell
r2.glyph.fill_color = "red"
push_notebook()
python
# this will update the immediately previous plot circle color with an explicit handle
r2.glyph.fill_color = "blue"
push_notebook(handle=t3)