How to filter labels / labelset by the view? Can't work out how to make labels for data that the view has filtered out go away

I’ve set up labelset surprisingly easily and it’s all working as intended except it’s showing for source = source, and I’d like it to only show values that correspond to datum that have made it into the view.

There was no view = view option in the labelset options, and playing around with the x and y values didn’t work. Is there some kind of ‘view.[whatever]’ code I can put into the x and y values? Or is there some other kind of trickery?

Here’s a simplified version of the code showing it in action:

from bokeh.plotting import figure, show
from bokeh.models import CustomJSFilter, CDSView, ColumnDataSource, CustomJS, LabelSet
from bokeh.models.widgets import CheckboxGroup
from bokeh.layouts import layout
data = dict(Apples=[97, 34, 23, 6, 26, 97, 21, 92, 73, 10, 92, 14, 77, 4],
            Bananas=[87, 63, 56, 38, 57, 63, 73, 56, 30, 23, 66, 47, 76, 15],
            Oranges=[21, 65, 86, 39, 32, 62, 46, 51, 17, 79, 64, 43, 54, 50],
            Category = ['A', 'B', 'B', 'C', 'A', 'C', 'B', 'C', 'C', 'B', 'A', 'A', 'B', 'B'])
Categories = ['A', 'B', 'C']
source = ColumnDataSource(data=data)
checkbox_group = CheckboxGroup(labels= Categories, active = [0])
checkbox_group.js_on_change("active", CustomJS(code="source.change.emit();", args=dict(source=source)))
custom_filter = CustomJSFilter(args=dict(source=source, checkbox_group = checkbox_group), code=
'''var indices = [];
for (var i = 0; i < source.get_length(); i++){
    if (>checkbox_group.labels[i]).includes(['Category'][i])
   ){ indices.push(true);
    } else {indices.push(false);}}return indices;''')
view = CDSView(source=source, filters=[custom_filter])
p = figure()'Oranges', 'Bananas', source=source, view=view, size=20, fill_color = 'red')
labels = LabelSet(x='Oranges', y='Bananas', text='Apples', level='glyph', source=source, render_mode='canvas')
controls = [checkbox_group]
l = layout([[controls, p]], sizing_mode="stretch_both")

Once again thank you for all the help!

Edit: saw that the title has a typo at the end, tried to fix it, and learned titles can’t be edited. How embarrassing…

Hey has anyone had a chance to look at this?

There’s not currently any mechanism to fiter LabelSet or utilize a view with it. Your best bet for now is probably to have a column to control alpha and make the ones that should be filtered out be invisible by setting to zero.

Also, I edited the title. I’m guessing that’s a feature that becomes available as user level increases but I will see if I can enable it for everyone including newer users.