Linked models via CDS distinguish source of change of selection

Hi,

I have two linked elements (a Scatter plot and a DataTable) sharing the same source CDS and want to trigger different behaviour in a python callback function on change of selected.indices depending on which element the selection is done on. Is there a way of doing so? Such information doesn’t seem to be stored in CDS.

Many thanks,
Ni

There is no kind of associated provenance information available.

For one thing, selections do not have to originate from glyphs at all, they can be created programmatically by simply assigning to the selection indices. You could imagine having a selected.last_selector property that a glyph could set with itself to indicate it made the last selection. But there’s nothing to stop anyone from just setting the selection indices in code sometime later, and which point the old value of last_selector is still there, but would be a lie. So that would just too unreliable and invite problems.

Another option is that selection events could potentially include this information, and that is because events (as opposed to properties) are “fire and forget”. There’s no chance for the value to be “out of date” because it only exists on the event, which only happens once at the time the selection is made. This is a possibility nowadays because the concept of events was added in the last few years, but it was not possible at the time sources and selections were originally implemented.

Please feel free to open a GitHub development discussion to raise the possibility of adding this as a feature. Unfortunately, I don’t have any good workaround to suggest for the immediate term.

Thank you Bryan for the detailed reply and sharing your thoughts. Including that information in selection event looks indeed like the right way to do it. Conceptually it could apply to all events, which might reduce or eliminate the need for global variables in python callback functions, but that seems too much of a change. I am currently very new to Bokeh and will read more to raise anything meaningful. At the moment I am going with two extra buttons one for each element to trigger the desired post-selection effect.

Many thanks,
Ni

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.