Reputation: 86
I have a ColumnDataSource that describes the data for a DataTable and I want to have an event that does something when I edit a cell in that DataTable. I setup the event on the data attribute of my ColumnDataSource and I want to get the difference between the old and new values of the attribute.
The problem is that both values are the same. How can I get the new and old values after I edit the table cell?
My code:
from bokeh.models import ColumnDataSource, DataTable, TableColumn, StringEditor
from bokeh.plotting import figure, curdoc
from bokeh.layouts import column
def cluster_name_changed(attr, old, new):
print(old)
print(new)
cluster_field = 'CLUSTER'
table_clusters_source = ColumnDataSource(data=dict(cluster_no=[1, 2, 3]))
columns_clusters = [TableColumn(field='cluster_no',
title="Cluster Name",
editor=StringEditor())]
table_clusters = DataTable(source=table_clusters_source,
columns=columns_clusters,
width=300,
height=200,
editable=True)
table_clusters_source.on_change('data', cluster_name_changed)
curdoc().add_root(column(table_clusters))
and the output is (when I update the third cell from "3" to "third"):
{'cluster_no': [1, 2, 'third']}
{'cluster_no': [1, 2, 'third']}
Upvotes: 1
Views: 782
Reputation: 34568
The old
and new
parameters work great with simple scalar properties (i.e. whose values are numbers, strings, colors, etc). However they do not work function with ColumnDataSource, and this is a known and documented limitation (tho I don't have a reference offhand). The reason is that making old
and new
function for ColumnDataSource can makes things unusably slow and explode memory usage.
Upvotes: 1