When ‘y’ change, I want automatically calculate fft(signal_src.data[‘y’]) and save in ‘ys’ column,
How exactly i can do that? I tryied use on_change(), but attr_change() don’t call then y parameter is changed.
First of all, why do you need to save it? If you don’t really need to have it saved in the data source, then you should be able to use a custom version of Transform or Expression. To be honest, I don’t really understand the difference between them, but one of them could definitely be used.
I must to save it, because i will draw ‘ys’ on another figure and will change ‘ys’.
Can you tell me, please, why on_cnahge didn’t work correct with ColumnDataSource.data?
I cannot really tell anything because you didn’t provide any code apart from a single call to on_change. I would be able to give some answer if you can provide a minimal working example that I can run on my side without having to change it.
So the callback is called once, when you call add_signal. It’s not called for the np.array mutations simply because Bokeh doesn’t care about NumPy. For Bokeh to understand that you have changed something, you have to explicitly change data sources. Call stream, call patch, directly assign data, or something else.
You see the changed data because you have changed it in-place. Bokeh synchronizes data only after the execution is returned back to the event loop - for your particular code it’s after all the statements have been executed. With that being said, I don’t think it’s a good thing - it will make it much harder to debug later. I wouldn’t rely on such behavior at all, I’d stay away from mutating shared data.
Regarding your question. It’s not possible to add a column, add some data to a different column, and expect the first one to be populated automatically. That’s because columns in column data sources need to always have the same length. There are two alternatives, if you want to stay in Python and not implement the FFT in JavaScript:
Populate the ys column yourself whenever you change the y column
Create a second data source just for the ys column and sync the data one way. So, when the y changes in the first data source, you’d compute and assign the ys values in the second data source. You can do that in your attr_change method.