I hit a problem with JS callback based selections in version 13, but discovered it still worked in an older version (0.12.10). I narrowed it down to a change in 0.12.15 which I suppose might be related to Make .selected a proper Bokeh model · Issue #6845 · bokeh/bokeh · GitHub
This stylised example was lifted straight from the v13 doc’s, and simply forces the selection of point 2 on the chart no matter which point is chosen.
What am I missing here?
from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.models.tools import HoverTool, TapTool
from bokeh.io import reset_output, output_file, save
import pandas as pd
s = ColumnDataSource(pd.DataFrame({‘x’: [1, 2, 3, 4, 5], ‘y’: [2, 5, 8, 2, 7]}))
plot = figure(plot_width=400, plot_height=400, tools=, title=“Select a circle”)
renderer = plot.circle(‘x’, ‘y’, source=s, size=50,
# set visual properties for selected glyphs
selection_color="firebrick",
# set visual properties for non-selected glyphs
nonselection_fill_alpha=0.2,
nonselection_fill_color="blue",
nonselection_line_color="firebrick",
nonselection_line_alpha=1.0)
tap_code = “”"
console.log(source.selected[‘1d’].indices);
source.selected[‘1d’].indices = [2];
source.change.emit();
console.log(source.selected[‘1d’].indices);
“”"
tap_callback = CustomJS(code = tap_code, args={‘source’: s})
plot.add_tools(TapTool(callback=tap_callback))
output_file(r’C:\data\test.html’)
save(plot)
reset_output()
``