Bokeh 2.0: Replacement for button.callback

Hello there,

the same piece of code has worked since before Bokeh 1.0, but now its broken due to a deprecation in 2.0: “Additionally, the callback property is removed from all Bokeh models except CustomAction , HoverTool TapTool , and OpenURL . Instead, the more general js_on_change or js_on_event methods should be used”

Before I go through the trouble of creating a minimal example, I’ll hope someone might point me in the right direction. I just want to attach a CustomJS callback to a button press. With this I have created buttons for uploading and downloading data. In pseudocode:

source = ColumnDataSource()
button = Button()
code_upload = """some JavaScript code"""
button.callback = CustomJS(args=dict(source=source), code=code_upload)

Now, “button.callback” does not work anymore, of course. Simply trying to replace that with button.js_on_change or button.js_on_event yields the following error:

  File "C:\Users\...\anaconda3\envs\bokeh_test\lib\site-packages\bokeh\core\", line 273, in __setattr__
    if name in props or (descriptor is not None and descriptor.fset is not None):
AttributeError: 'function' object has no attribute 'fset'

Is something like this supposed to work, or do I need a completely new approach to solve this?

For buttons the new function should be js_on_click:

b = Button(...)

Thanks for the fast reply, everything works fine now!

1 Like