bokeh / ipywidgets_bokeh

Allows embedding of Jupyter widgets in Bokeh applications.
BSD 3-Clause "New" or "Revised" License
24 stars 11 forks source link

Not working with anywidget: Class null not found in module @jupyter-widgets/base@2.0.0 #89

Closed MarcSkovMadsen closed 1 year ago

MarcSkovMadsen commented 1 year ago

anywidget is a new way of developing ipywidgets with a claim for being easier and more modern. For example mapwidget is built on top of anywidget.

I reported in https://github.com/bokeh/ipywidgets_bokeh/issues/88 that mapwidget.cesium is not working with ipywidgets-bokeh and Panel. So I thought I would try out a basic anywidget example. And I can see that it raises the same issue.

Reproducible Example

pip install panel==0.14.4 ipywidgets-bokeh==1.3.0 anywidget==0.2.0

script.py

import anywidget
import traitlets

import panel as pn

pn.extension("ipywidgets")

class CounterWidget(anywidget.AnyWidget):
    _esm = """
    export function render(view) {
      let getCount = () => view.model.get("count");
      let button = document.createElement("button");
      button.classList.add("counter-button");
      button.innerHTML = `count is ${getCount()}`;
      button.addEventListener("click", () => {
        view.model.set("count", getCount() + 1);
        view.model.save_changes();
      });
      view.model.on("change:count", () => {
        button.innerHTML = `count is ${getCount()}`;
      });
      view.el.appendChild(button);
    }
    """
    _css="""
    .counter-button { background-color: #ea580c; }
    .counter-button:hover { background-color: #9a3412; }
    """
    count = traitlets.Int(0).tag(sync=True)

counter = CounterWidget()
pn.panel(counter).servable()
panel serve script.py

Open http://localhost:5006/script and see the exception in the browser console.

image

Class null not found in module @jupyter-widgets/base@2.0.0
ndmlny-qs commented 1 year ago

@MarcSkovMadsen I can get your example to run in Jupyter, but I do get the same error you mention when running panel serve ....

ipy-bk-issue89.webm

I'll investigate more and see what I can find.

MarcSkovMadsen commented 1 year ago

Works with Solara. See https://twitter.com/maartenbreddels/status/1662550931047604225?s=46&t=QCeLnYcdhHHHwawHQ7y8xA

MarcSkovMadsen commented 11 months ago

I can confirm Anywidget now works with Panel. See https://discourse.holoviz.org/t/panel-works-with-anywidget/6466