Trigger CustomJS from a Python callback

Hi community,
I have a working app that runs javascript code on a button click -
button.js_on_click(CustomJS(args=dict(source=data), code=code))
where data is a ColumnDataSource object.

However I would like to instead trigger a Python callback on the button click -
button.on_click(func) and then within func in Python do two things:
(1) modify data according to other values from the app (not an issue)
(2) execute code as CustomJS(args=dict(source=data_modified), code=code)

Are you aware if Step (2) as above is even possible? Within func I can create the CustomJS object but then I am not sure how to get it to run as it would if connected with button.js_on_click. Happy to provide an MRE, I usually do, was thinking maybe you’d know based on only these details in this case… thanks for the support!

There is not presently any official “RPC” mechanism to directly invoke JS code from Python. The typical way folks do something like this is to create an object of some sort, in order to trigger a change or event callback on. Subclassing a DataModel is a good option for this.