Repository: holoviz/holoviews

Issue:
Empty output in Colab
#### ALL software version info
Google Colab

```
sys.version_info:	sys.version_info(major=3, minor=10, micro=12, releaselevel='final', serial=0)
ipywidgets.__version__:	8.1.1
bokeh.__version__:	3.3.2
jupyter_bokeh.__version__:	3.0.7
holoviews.__version__:	1.17.1
```
   
#### Description of expected behavior and the observed behavior
I'm trying to run the demo for the `BoxEdit` module, but when I run the demo nothing is shown


#### Complete, minimal, self-contained example code that reproduces the issue

```
!pip install holoviews --quiet
!pip install jupyter_bokeh --quiet

import holoviews
holoviews.extension('bokeh', logo=False)
from bokeh.plotting import output_notebook
output_notebook(hide_banner=True)

from google.colab import output
output.enable_custom_widget_manager()
```

This works:
```
%output size = 200
holoviews.extension('bokeh')

boxes = holoviews.Rectangles(
    [(0, 0, 1, 1), (2, 3, 4, 6), (0.5, 2, 1.5, 4), (2, 1, 3.5, 2.5)])
boxes.opts(
    holoviews.opts.Rectangles(
        fill_alpha=0.5,
        height=400,
        width=400))
```

Nothing is shown for this:
```
%output size = 200
holoviews.extension('bokeh')

boxes = holoviews.Rectangles(
    [(0, 0, 1, 1), (2, 3, 4, 6), (0.5, 2, 1.5, 4), (2, 1, 3.5, 2.5)])
box_stream = holoviews.streams.BoxEdit(source=boxes)
boxes.opts(
    holoviews.opts.Rectangles(
        fill_alpha=0.5,
        height=400,
        width=400))
```



#### Stack traceback and/or browser JavaScript console output
Looking in the Chrome develop tools console

```
Error has occurred while trying to update output.     output_binary.js:173
message: 'Widget @bokeh/jupyter_bokeh BokehModel is not supported',
Stack: CustomError: Widget @bokeh/jupyter_bokeh BokehModel is not supported
    at new Bk (https://ssl.gstatic.com/colaboratory-static/common/b124d179c25e30ffc6a1ff293e85eba8/output_binary.js:168:471)
    at wa.eval [as h] (https://ssl.gstatic.com/colaboratory-static/common/b124d179c25e30ffc6a1ff293e85eba8/output_binary.js:166:142)
    at za (https://ssl.gstatic.com/colaboratory-static/common/b124d179c25e30ffc6a1ff293e85eba8/output_binary.js:11:141)
    at Ba.next (https://ssl.gstatic.com/colaboratory-static/common/b124d179c25e30ffc6a1ff293e85eba8/output_binary.js:11:440)
    at eval (https://ssl.gstatic.com/colaboratory-static/common/b124d179c25e30ffc6a1ff293e85eba8/output_binary.js:12:319)
    at new Promise (<anonymous>)
    at Ca (https://ssl.gstatic.com/colaboratory-static/common/b124d179c25e30ffc6a1ff293e85eba8/output_binary.js:12:212)
    at y (https://ssl.gstatic.com/colaboratory-static/common/b124d179c25e30ffc6a1ff293e85eba8/output_binary.js:12:351)
    at yk (https://ssl.gstatic.com/colaboratory-static/common/b124d179c25e30ffc6a1ff293e85eba8/output_binary.js:166:51)
    at new zk (https://ssl.gstatic.com/colaboratory-static/common/b124d179c25e30ffc6a1ff293e85eba8/output_binary.js:165:1730)
```
#### Screenshots or screencasts of the bug in action
<img width="738" alt="image" src="https://github.com/holoviz/holoviews/assets/129072/36011584-cd4d-4bc4-98ba-a4360093e025">

### Other things to note
This code was working as is on google colab in August 2023, but is not now working in December 2023

- Note that running the code brings up snippets suggesting adding the code:

```
from google.colab import output
output.enable_custom_widget_manager()
```

However this has no effect

- Using the latest developer version of holoviews from github had no effect 


### Other things I've tried
I found this [issue](https://github.com/googlecolab/colabtools/issues/3020) on colabtools github, **_Default ipywidgets don't show up in notebooks_**

This issue suggests that "Downgrading ipywidgets to 7.7.1" may help

I tried 
```
!pip install ipywidgets==7.7.1
```

The current version of `jupyter-bokeh` is `3.0.7` and requires `ipywidgets==8.*`
The most current version of `jupyter-bokeh` that supports `ipywidgets==7.7.1` is version `3.0.2`. 
```
!pip install jupyter_bokeh==3.0.2
```
However in going from `3.0.2` => `3.0.7` there was a bug fixed to be compatible with the current version of bokeh `3.3.2`, namely
```
standalone_docs_json_and_render_items() takes 1 positional argument but 2 were given
```

This fix can be monkey patched back into `jupyter-bokeh` version `3.0.2`, so all together the code looks like this:


```
!pip install ipywidgets==7.7.1
!pip install jupyter_bokeh==3.0.2

import bokeh
import bokeh.model
import jupyter_bokeh
import jupyter_bokeh.widgets

# use functools.wraps to keep the @classmethod decorator 
import functools
@functools.wraps(jupyter_bokeh.widgets.BokehModel._model_to_traits)
def _model_to_traits(cls, model):
    if model.document is None:
        document = bokeh.document.Document()
        document.add_root(model)
    (docs_json, [render_item]) = bokeh.embed.util.standalone_docs_json_and_render_items(
        [model],
        suppress_callback_warning=True)
    render_bundle = dict(
        docs_json=docs_json,
        render_items=[render_item.to_json()],
        div=bokeh.embed.elements.div_for_render_item(render_item),
    )
    return render_bundle

jupyter_bokeh.widgets.BokehModel._model_to_traits = _model_to_traits

!pip install holoviews --quiet

from bokeh.plotting import output_notebook
output_notebook(hide_banner=True)

import holoviews
holoviews.extension('bokeh', logo=False)
```

However downgrading to ipywidgets did not resolve the problem







Discussion:
Can you try installing the latest holoviews (1.18.1) + panel (1.3.6)?

After that, can you then run `holoviews.show_versions()` and paste the output?
That doesn't seem to solve the problem.

Here is what I tried:
```
!pip install jupyter_bokeh

!pip install holoviews==1.18.1
!pip install panel==1.3.6

import holoviews
holoviews.extension('bokeh', logo=False)

from bokeh.plotting import output_notebook
output_notebook(hide_banner=True)

from google.colab import output
output.enable_custom_widget_manager()
%env HV_DOC_HTML=true
```

```
%output size = 200
holoviews.extension('bokeh')

boxes = holoviews.Rectangles(
    [(0, 0, 1, 1), (2, 3, 4, 6), (0.5, 2, 1.5, 4), (2, 1, 3.5, 2.5)])
box_stream = holoviews.streams.BoxEdit(source=boxes)
boxes.opts(
    holoviews.opts.Rectangles(
        fill_alpha=0.5,
        height=400,
        width=400))
```
And it is giving the same no-output and Chrome developer tools console error.







```
Python              :  3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Operating system    :  Linux-6.1.58+-x86_64-with-glibc2.35
Panel comms         :  colab

holoviews           :  1.18.1

bokeh               :  3.3.2
colorcet            :  3.0.1
cudf                :  -
dask                :  2023.8.1
datashader          :  -
geoviews            :  -
hvplot              :  -
ibis                :  6.2.0
IPython             :  7.34.0
jupyter_bokeh       :  3.0.7
jupyterlab          :  -
matplotlib          :  3.7.1
networkx            :  3.2.1
notebook            :  6.5.5
numba               :  0.58.1
numpy               :  1.23.5
pandas              :  1.5.3
panel               :  1.3.6
param               :  2.0.1
PIL                 :  9.4.0
plotly              :  5.15.0
pyarrow             :  10.0.1
scipy               :  1.11.4
skimage             :  0.19.3
spatialpandas       :  -
streamz             :  -
xarray              :  2023.7.0
None
```

Did anyone figure out how to resolve this issue?
I can get figures to show by wrapping them in `pn.panel`:

![image](https://github.com/holoviz/datashader/assets/19758978/240f2269-a3e8-4c18-8152-82a26ea8afe0)

<details>
  <summary><code>hv.show_versions </code> </summary>

``` yaml
Python              :  3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Operating system    :  Linux-6.1.58+-x86_64-with-glibc2.35
Panel comms         :  colab

holoviews           :  1.18.3

bokeh               :  3.3.4
colorcet            :  3.1.0
cudf                :  -
dask                :  2023.8.1
datashader          :  0.16.1
geoviews            :  -
hvplot              :  -
ibis-framework      :  8.0.0
IPython             :  7.34.0
jupyter_bokeh       :  4.0.4
jupyterlab          :  -
matplotlib          :  3.7.1
networkx            :  3.3
notebook            :  6.5.5
numba               :  0.58.1
numpy               :  1.25.2
pandas              :  2.0.3
panel               :  1.3.8
param               :  2.1.0
pillow              :  9.4.0
plotly              :  5.15.0
pyarrow             :  14.0.2
pyviz_comms         :  3.0.2
scikit-image        :  0.19.3
scipy               :  1.11.4
spatialpandas       :  -
streamz             :  -
tsdownsample        :  -
xarray              :  2023.7.0

```

</details>
So this seems to work:

```python
from panel.io.notebook import load_notebook
load_notebook()
hv.Curve([1, 2, 3])
```

For some reason the `load_notebook` call in `holoviews.plotting.renderer.Renderer._render_ipywidget` isn't being executed.

Resolving patch:
diff --git a/holoviews/plotting/renderer.py b/holoviews/plotting/renderer.py
--- a/holoviews/plotting/renderer.py
+++ b/holoviews/plotting/renderer.py
@@ -389,8 +389,9 @@ def components(self, obj, fmt=None, comm=True, **kwargs):
                 src is source or (src._plot_id is not None and src._plot_id == source._plot_id)
                 for src, streams in registry for s in streams
             )
+        if config.comms == 'colab':
+            load_notebook(config.inline)
         embed = (not (dynamic or streams or self.widget_mode == 'live') or config.embed)
-
         if embed or config.comms == 'default':
             return self._render_panel(plot, embed, comm)
         return self._render_ipywidget(plot)


Test patch: