Skip to content

'Models must be owned by only a single document' issue #167

@axil

Description

@axil

The following code that intermixes two BokehModel instances with an ipywidget instance

import bokeh.plotting as bp
import bokeh.models as bm
import ipywidgets as ipw
from jupyter_bokeh import BokehModel
p = bp.figure()
src = bm.ColumnDataSource(data={'x': [1,2], 'y': [3,4]}) 
p.line(source=src)
radio = bm.RadioGroup(labels=['a', 'b'], active=0)
label = ipw.Label('c')
callback = bm.CustomJS(args=dict(data_src=src))
radio.js_on_change('active', callback)
ipw.VBox([
    BokehModel(p),
    BokehModel(radio), 
    label,
])

generates the following error:

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

Supposedly the problem is with jupyter_bokeh because

import bokeh.layouts as bl
bp.show(bl.column(p, radio))

works fine.

It is similar to #154, and I understand that

ipw.VBox([
    BokehModel(bl.column(p, radio)),
    label,
])

is a workaround, but this trick is not always possible, for example, it is not possible for the following layout:

ipw.VBox([
    BokehModel(p),
    ipw.HBox([
          BokehModel(radio), 
          label,
    ]),
])

and the main difference from issue 154 is that I don't understand which model is being 'shared' here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions