I am working on a tool for manual classification which changes the property of certain dot(color in my case) chosen in a scatter plot by bokeh. I changed the source data in callback by s.data = d2 and s.change.emit() but both failed. I thought such operation will change source.data, but when I print source.data, actually nothing happens. The dots' color in the plot changes as expected though. Here is my related code:
DF = pd.read_csv(csv_path)
s = ColumnDataSource(DF_file)
p = figure(plot_width=500, plot_height=500, tooltips=TOOLTIPS,tools="lasso_select, tap", title="manual classification")
circles = p.circle('x', 'y', color='color', size=10, source=s, line_alpha=0.6,fill_alpha=0.6)
s.callback = CustomJS(args=dict(s1=s), code="""
var inds = cb_obj.selected.indices;
var d1 = s1.data;
for (var i = 0; i < inds.length; i++)
{d1['color'][inds[i]] = 'green';}
s1.change.emit();
""")
Both print(s.data) and the csv file saved from s.to_csv(xxx) shows no change to the original input data.
Also, I wonder how does callback work to change the plot's data while leave the data in python unchanged when the data in python is the data passed to it in args=(s1=s)
.