I asked this on StackOverflow here but think maybe this group will be better able to get me to a solution. Here’s my issue:
I want to be able to make a selection (lasso, box_select) of points in a streaming Bokeh scatterplot that will be remembered when the figure updates (e.g., with new data in the time series).
I think this will require me to be able to access the list of the indices of currently selected points, but I can’t figure out how to. Here’s an example where I try (slightly modified from the example at http://bokeh.pydata.org/en/latest/docs/user_guide/server.html#streaming-data-with-the-server). Note that selected points are deselected when the plot updates to the new streamed (shuffled in this example) data.
import time from random import shuffle from bokeh.plotting import figure, output_server, cursession, show # prepare output to server output_server("remember_selected") p = figure(plot_width=400, plot_height=400,tools="lasso_select,box_select,help") p.scatter([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], name='ex_line') show(p) # create some simple animation.. # first get our figure example data source renderer = p.select(dict(name="ex_line")) ds = renderer. data_source while True: # Update y data of the source object shuffle(ds.data["y"]) #Can I access currently selected points? (NO!) print ds.selected['2d'] print ds.selected['1d'] print ds.selected['0d'] # store the updated source on the server cursession().store_objects(ds) time.sleep(2.)
Thanks for any help you can provide!