☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Throttled update for Selections

Community Support
fstroth
fstroth

Hey, is there a way to throttle the update of a selection. For example if I have a lasso_select and start selecting points than with every new selected or unselected point the callback will be triggered (simple example below). What I want to achieve is that the callback is trigger after a mouse up when I am done with the selection. Is there a way to achieve this?

import pandas as pd
from bokeh.plotting import show, figure
from bokeh.models import ColumnDataSource

source = ColumnDataSource(pd.DataFrame({"x": [1,2], "y": [1,2]}))
source.selected.on_change("indices", lambda attr, old, new: print("test"))

p = figure(tools="lasso_select")
p.scatter("x", "y", source=source)

show(p)
⌁   Link to post
hageldave
hageldave

What if I need both behaviors? For example I have some callbacks that are expensive and some that are cheap. So I want all cheap callbacks (e.g. triggering update of a label that says how many points are selected) to immediately trigger while dragging the mouse, but the expensive ones (e.g. that cause some computation involving the selected points) to only trigger on mouse button release.

Right now I think I need to do the expensive triggering manually, e.g., by pressing a button that says “run computation on selection”.

⌁   Link to post
Bryan
Bryan

Well, there is the SelectionGeometry event that you can respond to with on_event (or with js_on_event). It has a final property that will be set to True when the geometry is “finalized” (e.g. on mouse-up). However, you will have to experiment and try it out because one thing I don’t know offhand is whether this event is guaranteed to be emitted before or after the actual corresponding selection on the data source is updated.

Edit: it does look like the geometry event is sent last, after the data source selections are updated, which is probably what you’d want.

⌁   Link to post

End of archived discussion · Replies are disabled