1

This is a pretty simple thing to do I imagine, but I'm not sure how to do it. I have a data table with three columns. Two are numerical values that are plotted, and one is strings. I want the user to be able to input into a field, and the corresponding row in the DataTable and the point on the plot to be selected/highlighted.

I think I need to use source.selected.indices, or possibly a CustomJS callback.

Can anyone help?

from random import randint from bokeh.io import output_file, show from bokeh.layouts import gridplot, row from bokeh.models import ColumnDataSource from bokeh.models.widgets import DataTable, TableColumn, TextInput search_words = TextInput(title="Search for country") data = dict( x=[randint(0, 100) for i in range(10)], y=[randint(0, 100) for i in range(10)], countries = ["France","Spain","Germany","Italy","Portugal","Poland","Russia","Bulgaria","Sweden","Belgium"] ) source = ColumnDataSource(data) columns = [ TableColumn(field="x", title="x"), TableColumn(field="y", title="y"), TableColumn(field="countries", title="Countries"), ] TOOLS = "pan,wheel_zoom,box_select,reset" fig = figure(plot_width=400, plot_height=400, tools=TOOLS) fig.circle('x', 'y', source=source,size=10,selection_color="red", hover_color="green") data_table = DataTable(source=source, columns=columns, width=400, height=280) p = gridplot([fig],[data_table], toolbar_location = "above") show(row(p, search_words)) 

plot

1 Answer 1

0

You are correct that using the show method to render your charts you would need to use custom JavaScript to have a widget on the chart update data sources. The show method renders whatever has been programmed in the Python as an HTML document, but once rendered the HTML document has no way to further interact with the Python code.

The alternative is to use the Bokeh server, as documented here. Very basically, you can put all your code in a file main.py, put that file in a folder with your project name, and then in the terminal of the parent directory of that project folder, run:

bokeh serve --show project_folder_name

You'll also need to write an on_change method for your text input as described here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.