Skip to main content
edited tags
Link
ChesuCR
  • 9.8k
  • 6
  • 58
  • 121
edited tags; edited title
Link
ChesuCR
  • 9.8k
  • 6
  • 58
  • 121

Add How to add a Callback to Bokeh DataTable?

Source Link
Kyle Siegel
  • 763
  • 1
  • 7
  • 8

Add Callback to Bokeh DataTable

I am trying to use Bokeh to make an editable DataTable that updates the source data when the data is edited. I started with the standard DataTable example here, and make the editable kwarg to true. Here is where I am at:

from datetime import date from random import randint from bokeh.models import ColumnDataSource, Callback from bokeh.models.widgets import DataTable, DateFormatter, TableColumn from bokeh.io import output_file, output_notebook, show, vform output_notebook() data = dict(dates=[date(2014, 3, i+1) for i in range(10)], downloads=[randint(0, 100) for i in range(10)]) source = ColumnDataSource(data) columns = [TableColumn(field="dates", title="Date", formatter=DateFormatter()), TableColumn(field="downloads", title="Downloads")] callback = Callback(args=dict(Source=source), code=""" console.log( '#cell edited')""") data_table = DataTable(source=source, columns=columns, width=400, height=280, editable=True) data_table.on_change(callback,source) show(vform(data_table)) 

This makes an editable data table, but I can't figure out how to get the callback to update the source data, or to configure the source data so that it automatically does that. I thought there was a way to automatically do that with ColumnDataSource, and after trying that tried to write a callback. However it appears the DataTable doesn't have a callback option, but it oddly has an on_change attribute.

Does anyone know how to do this?