Bokehjs js_property_callbacks

Writing directly to bokehjs (all javascript web application). It requires a bit of spelunking. But I can generally make progress (and I used Bokeh in my Python apps).

What is the magic to call js_property_callback? I want to capture the change in x_range on a figure.

The first two callbacks work (event callbacks). The property callbacks do not.

Thanks!

        figure.js_event_callbacks['pan'] = [{execute: onPan}];
        figure.js_event_callbacks['tap'] = [{execute: onTap}];
        figure.x_range.js_property_callbacks['change:end'] = [{execute: onChange}];
        figure.x_range.js_property_callbacks['change:start'] = [{execute: onChange}];
        figure.x_range.js_property_callbacks['change'] = [{execute: onChange}];

Those properties you are modifying are implementation details. Properly they should be made private, but there were some technical obstacles to doing that.

For model “on change” callbacks for Bokeh model properties, you can add callbacks the way that BokehJS does internally, e.g.

this.on_change(this.x_range_name, () => this._initialize_coordinates())

I am not sure there is currently any good way to add “event” callbacks in BokehJS. Relative to the Python bindings, the BokehJS API is not as well-developed. This is probably worth a GitHub Issue to request as a feature. cc @mateusz

Awesome. That works. Using on_change() as you suggested!

Any tips on capturing the “tap” in a more “official” way?

Thanks,
Paul

Well that’s my point is that there isn’t really any such way, currently. You can imitate what BokehJS itself does but that’s at the risk of using private/internal APIs or properties that may change. Specifically what I think you are missing in your original code is this bit:

That said, what might be a simpler thing to try first is to actually assign to js_event_callbacks not just update it in place:

figure.js_event_callbacks = new_events_dict

Bokeh can automagically detect real assignments, but can’t detect in-place modifications like you have in the OP. If you make a real assignment I think BokehJS will automatically take care of the model subscription bits.