I've taken the below code from another source - it is not my own code.
The code allows you to select a cell in the data table, and the 'downloads' data for that cell will chart based on the row of the cell selected.
How do I expand this code such that if I have multiple variables (eg. 'downloads' and 'uploads') and so more columns in the data table, I can chart data based on that cell (so where row AND column are important)? Alternatively, how can I define as a variable the column number of a selected cell (in the same way selected_row below can be used to define the row number)?
from datetime import date from random import randint from bokeh.models import ColumnDataSource, Column from bokeh.plotting import figure, curdoc from bokeh.models.widgets import DataTable, DateFormatter, TableColumn, Div import numpy as np data = dict(dates = [date(2014, 3, i + 1) for i in range(10)], downloads = [randint(0, 100) for i in range(10)]) d_source = ColumnDataSource(data) columns = [TableColumn(field = "dates", title = "Date", formatter = DateFormatter()), TableColumn(field = "downloads", title = "Downloads")] data_table = DataTable(source = d_source, columns = columns, width = 400, height = 280) def table_select_callback(attr, old, new): selected_row = new[0] download_count = data['downloads'][selected_row] chart_data = np.random.uniform(0, 100, size = download_count) p = figure(title = 'bla') r = p.line(x = range(len(chart_data)), y = chart_data) root_layout.children[1] = p d_source.selected.on_change('indices', table_select_callback) root_layout = Column(data_table, Div(text = 'Select Date')) curdoc().add_root(root_layout)