Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding callbacks after BokehModel creation #153

Open
axil opened this issue May 30, 2022 · 4 comments
Open

Adding callbacks after BokehModel creation #153

axil opened this issue May 30, 2022 · 4 comments

Comments

@axil
Copy link
Contributor

axil commented May 30, 2022

Hi,

The event callbacks registered before a call to BokehModel work fine:

def f(event):
    print('hi')
b = bm.Button()
b.on_click(f)
w = BokehModel(b)
w

Is it possible to register the callbacks after BokehModel has been created?

def f(event):
    print('hi')
b = bm.Button()
w = BokehModel(b)
b.on_click(f)    # or w._model.on_click
w
@axil
Copy link
Contributor Author

axil commented May 30, 2022

Ok. Got it:

def f(event):
    print('hi')
b = bm.Button()
w = BokehModel(b)
b.on_click(f)
w.render_bundle = w._model_to_traits(b)
b._update_event_callbacks()
w

@axil axil closed this as completed May 30, 2022
@bryevdv
Copy link
Member

bryevdv commented May 31, 2022

Just noting that private APIs can change or be removed at any time so using those methods is purely at your own risk.

We could consider crafting a supported, public API for this, but I think we'd need to understand the use-case better. The intended usage of BokehModel is to be a "last mile" bridge for certain jupyter integrations. I.e. the intent is to set up all your Bokeh models normally up front, then only use BokehModel as the last step.

@axil
Copy link
Contributor Author

axil commented Jun 2, 2022

This makes the following layout impossible to implement:

Bokeh plot1
Ipywidget Slider
Bokeh plot2

(or rather a horizontal version of this widget sequence)

I realize that I could use the bokeh slider instead of the ipywidgets one. But not all ipywidget widgets have their counterparts in bokeh.

@mattpap mattpap reopened this Jun 2, 2022
@mattpap
Copy link
Contributor

mattpap commented Jun 2, 2022

We need to let BokehModel listen to the underlying model's changes and refresh its render_bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants