I’m trying to create a web app that simply allows me to select some points and then remove them from the plot by pushing a button. The code I have below does this except that after the selected points are removed other points then show as though they are now selected. I thought perhaps manually changing the list of selected indices to an empty list would accomplish this but that doesn’t work. Any ideas?
remove.py
import numpy as np
from bokeh.io import curdoc
from bokeh.models import Button
from bokeh.plotting import figure, curdoc, vplot
xs = np.random.normal(loc=1.0, size=100)
ys = np.random.normal(loc=1.0, size=100)
TOOLS=“pan,wheel_zoom,box_select,lasso_select”
p = figure(tools=TOOLS, plot_width=600, plot_height=600, title=None, min_border=10, min_border_left=50)
r = p.scatter(xs, ys, size=3, color="#3A5785", alpha=0.6)
def callback():
for index in sorted(r.data_source.selected[‘1d’][‘indices’], reverse=True):
r.data_source.data[‘x’].pop(index)
r.data_source.data[‘y’].pop(index)
r.data_source.selected[‘1d’][‘indices’] = list() # this seemingly has no effect
r.data_source.trigger(‘data’, r.data_source.data, r.data_source.data)
button = Button(label=“Remove Points”)
button.on_click(callback)
put the button and plot in a layout and add to the document
curdoc().add_root(vplot(button, p))
``
Thanks!