Adapting bokehlab to bokeh 3.0

Hi, Brian recommended to post it here:

Bokehlab is a thin wrapper over Bokeh that makes it easier to use Bokeh in Jupyter notebook.

I’m trying to make my library that previously worked with 2.4.3 work with 3.x, too.

Originally (in 2.4.3) I extended the Figure class with

from bokeh.plotting.figure import Figure as BokehFigure

class Figure(BokehFigure):
    __subtype__ = "BokehlabFigure"
    __view_model__ = "Plot"
    __view_module__ = "bokeh.models.plots"

With the release of 3.0 this no longer works. I tried the following:

from bokeh.plotting._figure import figure as BokehFigure

class BokehlabFigure(BokehPlot):
    __subtype__ = "BokehlabFigure"
    __view_model__ = "Plot"
    __view_module__ = "bokeh.plotting._figure"

It fails with a warning

Warning: Duplicate qualified model declaration of 'Plot'. Previous definition: <class 'bokeh.models.plots.Plot'>

What does this warning mean and what is the best way to workaround it?

@mateusz made some changes around Model sub-classing for Bokeh 3.0 hopefully he can chime in here with some guidance.

Offhand though, I might suggest switching to a compositional design where you keep track of Bokeh objects internally, rather than trying to subclass them. Unfortunately the cross-runtime nature of Bokeh makes subclassing things, without also providing a corresponding JavaScript implementation, awkward.

The migration guide says that __subtype__ is deprecated and now DataModel should be used. Is there any example of how it can be used?

There are a couple of examples in the examples directory, e.g.

examples/plotting/ is a good starting point for this. One thing it doesn’t show, is that data models can extend existing models and define new properties, so you can write something like this:

class MyPlot(Plot, DataModel):
    my_proproperty = Int()

This works for figure as well.

Note that __subtype__ was removed. __view_model__ and __view_module__ are still in use, but should be used sparingly. Data models don’t require those properties in typical usage.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.