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

Allow to share a Document between multiple BokehModels #154

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

Allow to share a Document between multiple BokehModels #154

axil opened this issue May 30, 2022 · 4 comments

Comments

@axil
Copy link
Contributor

axil commented May 30, 2022

p1 = figure()
p2 = figure(x_range=p1.x_range)
ipw.VBox([BokehModel(p1), BokehModel(p2)])

generates

RuntimeError: Models must be owned by only a single document, DataRange1d(id='14198', ...) is already in a doc

Is there a fix or a workaround maybe?

@axil
Copy link
Contributor Author

axil commented May 30, 2022

I've found a workaround:

BokehModel(column(p1,p2))

Is it the only possible way to solve it?

@bryevdv
Copy link
Member

bryevdv commented May 31, 2022

Putting the plots together in a Bokeh layout was going to be my only suggestion. "Being in a document together" is the foundational definition that is essentially identical with "being able to share pieces together". But each BokehModel creates a new document for all the models it ends up containing. So, if you want to share pieces between different plots, those plots need to be configured on the same BokehModel, so that they are both in the same Document.

@axil
Copy link
Contributor Author

axil commented Jun 2, 2022

I see. Maybe there's an alternative way of linking the plot ranges on the js level without sharing the Range object between the plots? Or it will hit the same limitation?

@mattpap
Copy link
Contributor

mattpap commented Jun 2, 2022

Maybe there's an alternative way of linking the plot ranges on the js level without sharing the Range object between the plots?

You can always link manually, by setting up event listeners and updating related plots, but that defies the point of using bokeh (well, partially at least). This is a current limitation that each embedded model constructs its own document, and, by design, there is no sharing between models belonging to different documents. However, I don't see any technical reason not to lift this limitation. Before that happens, your options are either to link manually or to use bokeh's layouts and wrap a whole layout as a BokehModel (as you already found out).

@mattpap mattpap changed the title Shared ranges do not work with BokehModel Allow to share a Document between multiple BokehModels Jun 2, 2022
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