How to add a glyph dynamically to a plot (Jupyter Notebook)


I would like to be able to add glyph(s) dynamically to a plot based on user’s selection without bokeh server (Jupyter Notebook). My attempt doesn’t give me a desired result.

from bokeh.models.widgets import Select

from bokeh.plotting import figure, show

from import push_notebook, output_notebook

from bokeh.models import ColumnDataSource

from bokeh.layouts import widgetbox

from bokeh.models.widgets import Select


source = ColumnDataSource(data=dict(x=[1,2,3], y=[5,3,8]))

p = figure(plot_width=600, plot_height=250)“x”, “y”, size=20, source=source)

def update(attr, old, new):

if new == “red”:[“z”] = [1, 1, 1]“x”, “z”, source=source, size=20)


select = Select(title=“Option:”, value=“blue”, options=[“blue”, “red”, “green”])

select.on_change(“value”, update)

show(column(widgetbox(select, width=50), p), notebook_handle=True)


Any comments/suggestions are highly appreciated.

Thank you for your time.