I want to get information about the selected data using the box select function of the bokeh.

Asked 5 months ago, Updated 5 months ago, 14 views

How do I retrieve information about the selected data using the box select function in the bokeh?

 from bokeh.layouts import gridplot
from bokeh.io import output_notebook, show
from bokeh.plotting import figure, output_file
from bokeh.models import ColumnDataSource

x = list(range(-20,21))
y0, y1 = [abs(xx) for xx in x], [xx**2 for xx in x]

# create a column data source for the lots to share

TOOLS="box_select, lasso_select, help"

# create a new plot and add a render
left=figure(tools=TOOLS, width=300, height=300)
left.circle('x', 'y0', source=source)

# create another new plot and add a render
right=figure(tools=TOOLS, width=300, height=300)
right.circle('x', 'y1', source=source)

p=gridplot([left, right]])


python bokeh

2022-09-30 11:30

1 Answers

The bokeh.models.CustomJS class allows JavaScript to retrieve information about selected objects.

p=gridplot([left, right]])

from bokeh.models import CustomJS
source.selected.js_on_change('indices', CustomJS(args=dict(s=source), code="""
    constinds = s.selected.indices;
    constd = s.data;


For example, if you select two points on a graph, the index of the selected point is printed to the browser console.

Enter a description of the image here

If you want information about the selected data to be reflected in the graph in some way, refer to the following document:

This method also requires knowledge of JavaScript.
If you want to complete with Python only, you must launch bokeh server.
For more information, please visit:

Run Environment

  • Python 3.9.7
    • bokeh2.4.7
    • jupyter 1.0.0
  • Firefox 94.0 (64bit)
  • XUbuntu 18.04
  • bokeh2.4.7
  • jupyter 1.0.0

2022-09-30 11:30

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.