Bokeh vbar with group counts after filtering with a CDSView

I’d like to create a Bokeh vertical bar chart (vbar) coupled with a scatter plot. I need to start from a given ColumnDataSource (then filtered with a CDSView), as this is only a part of a complex visualization and I need all the plots to be linked together.

The only tricky part for which I didn’t find anything about after extensive research is: how to show counts (i.e., the values provided in the top parameter of vbar) based only on data points that are both filtered AND selected in the scatter plot? Both the plots receive the same filters from which a view is created.

The documentation shows how to link selected points in different plots (by using the same ColumnDataSource object), how to filter them, and how to use vbar, but not all of them together.

Any hint? Thank you very much in advance.

Label/labelsets etc. are not glyphs but layouts… I’ve found this to be a little limiting/cumbersome at times but my go to workaround has been to make a separate source for the labels with the same indices as the main datasource, and use a customJS callback to trigger whenever a filter or selection gets applied, and have that JS callback iterate through the indices of your main source, and update the label datasource data accordingly with only the values of the indices of the main source that (in your case) are both selected and filtered.

Interested if there are better suggestions than this one…

Thank you @gmerritt123 for your response. Actually I’m not trying to use labels but somehow I need to count rows (after a groupby) to be shown in the vbar. So yesterday I came up with a similar idea to what you are proposing (multiple sources, callbacks to make the updates consistently) but I’m struggling a bit. Do you have some code to share as an example? Thank you very much!

Is the groupby happening each time a new filter gets applied… i.e. are you aggregating in a callback? How are you implementing the callbacks, with standalone JS or Bokeh serve?

Either way, I’m guessing all you’re needing to do is update the “top” parameter of the vbar with the results of the callback?

Writing out and posting a minimal reproducible working example has been most productive in terms of distilling for me the core of what i’m trying to do and in illustrating to others my exact question/roadblock. Oftentimes by the time I’ve written out my example I find the answer myself :smiley: