☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Updating a calculated field on edits in DataTable

Community Supportserver
Nitin_Chaudhary
Nitin_Chaudhary

I have an editable DataTable with a column z that gets calculated by running some calculations (fast but non-trivial) on another column x. (example: z = x^2). I want to make the updates live in the z column to changes in row values for the x column. I am running this use case with a bokeh server.

I can listen to changes in x and y columns using the on_change callback on the data property for the underlying cds. This works as expected. But then how do I trigger a change in the z column? I can’t update the cds from its own on_change callback because that creates an infinite recursion situation.

I have read Data table editing - change when user changes input value - Community Support - Bokeh Discourse – But this doesn’t work because there is no patching event on the python server side as mentioned in the discussion here python - Callback to datatable when user changes a content of cell - Stack Overflow

⌁   Link to post
Bryan
Bryan

You might be able to call source.patch from CDS on change callback without recursion. I am not sure though, you would just have to try. If that does not work ten this probably points to needing new development to actually, properly support derived expressions for table columns.

⌁   Link to post
Bryan
Bryan

I’m afraid that there is probably no simple or direct solution at present, then [1]. Please feel free to open a GitHub development discussion to propose a new feature.


  1. hacky, off-the-cuff ideas: managing an am_updating boolean flag to stop recursion, or updating something besides the CDS, and then responding with a JS callback on that other other thing to update the CDS using BokehJS APIs, which I might help. ↩︎

⌁   Link to post
_jm
_jm

In situations where this was unavoidable/necessary in the past, I leveraged the tags property of objects to implement a lightweight state machine.

For example like setting/unsetting a Boolean flag or a descriptor of the originator/source of the callback. That state can be checked on entering the callback and set to something else as necessary to cleanly handle the recursion.

Sorry I don’t have an example in front of me at the moment, but hopefully this gives some ideas.

⌁   Link to post
Bryan
Bryan

@_jm after so long trying to get them added, I forgot DataModels exist now. That’s what you can use instead of (ab)using tags or other random models properties. Here is an example:

bokeh/data_models.py at branch-2.4 · bokeh/bokeh · GitHub

And that could possibly be used by the OP as well:

  • first CDS (python) callback updates a data model property
  • second data models (JS) callback updates source.data in place, and calls source.change.emit()

I think that will cause the front end to up as desired, the drawback is that the change made on the JS side would not be refected back to Python. But if this is not important to you, then it should be workable.

⌁   Link to post
_jm
_jm

Great. I’ll check it out. I was not aware of this new feature as I’ve been narrowly focused on low-level details and cleanup in my apps.

I’m sure it has a place for me going forward; for the stream-of-thought reply above I was going back to examples where I was working in a server context and I absolutely wanted the python-side aware of the current state of everything in the client.

⌁   Link to post

End of archived discussion · Replies are disabled