Old and New parameters for on_change event of a ColumnDataSource have the same value

Hi,

I have a DataTable with editable cells and I want to do something with the old and new data when a cell is edited.

The problem is that both old and new parameters of my callback function have the same value (the new values), so I can’t track the changes between edits.

Is this expected? Am I missing something? Do you have any idea how can I get the old values (or the difference between edits)?

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 console output when I update the third cell from “3” to “third”:

{‘cluster_no’: [1, 2, ‘third’]}
{‘cluster_no’: [1, 2, ‘third’]}


I also [asked this question on StackOverflow](https://stackoverflow.com/questions/54987555/bokeh-old-and-new-parameters-for-on-change-event-of-a-columndatasource-have-the) so you can find a bit more information there.

This was tested with Bokeh versions 1.0.1 and 1.0.4.

Thank you for your help,
Madalin

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 cold can makes things unusably slow and explode memory usage.

Thanks,

Bryan

···

On Mar 4, 2019, at 11:55 PM, [email protected] wrote:

Hi,

I have a DataTable with editable cells and I want to do something with the old and new data when a cell is edited.
The problem is that both old and new parameters of my callback function have the same value (the new values), so I can't track the changes between edits.

Is this expected? Am I missing something? Do you have any idea how can I get the old values (or the difference between edits)?

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 console output when I update the third cell from "3" to "third":

{'cluster_no': [1, 2, 'third']}
{'cluster_no': [1, 2, 'third']}

I also asked this question on StackOverflow so you can find a bit more information there.

This was tested with Bokeh versions 1.0.1 and 1.0.4.

Thank you for your help,
Madalin

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e3854fbe-27e2-4e67-a101-ec941a0a9c49%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.