I am having trouble seeing where and how to set the selection (via a JS callback) on a plot that has two different lines plotted.
I have tried the three “indices” options but none work as desired. I see a selected_glyphs property, but that contains objects. I can’t see a simple array to populate with indexes.
Here is a simplified example, where you click the button to make the selection.
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.models.widgets import Button
from bokeh.layouts import row
from bokeh.io import reset_output, output_file, save
import pandas as pd
data = pd.DataFrame(
data={
‘a’: [1,1,2,2,1,1],
‘b’: [2,2,3,3,2,2],
‘index’: [0,1,2,3,4,5]}
)
source = ColumnDataSource(data)
plot = figure(plot_width=400, plot_height=400)
lines = [plot.line(x=‘index’, y=col, source=source) for col in ‘ab’]
for line in lines:
line.selection_glyph = Line(line_color=‘red’)
Button_code = CustomJS(args={‘source’: source}, code=’’’
console.log(source.selected);
source.selected.indices = [1];
‘’’
)
button = Button(callback=Button_code)
output_file(r’C:\data\test.html’)
save(row(plot, button))
reset_output()
``