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

Empty output in Colab #6049

Closed
momeara opened this issue Dec 22, 2023 · 5 comments · Fixed by #6269
Closed

Empty output in Colab #6049

momeara opened this issue Dec 22, 2023 · 5 comments · Fixed by #6269
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@momeara
Copy link

momeara commented Dec 22, 2023

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

image

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 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

@hoxbro
Copy link
Member

hoxbro commented Dec 22, 2023

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?

@momeara
Copy link
Author

momeara commented Dec 22, 2023

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

@hoxbro hoxbro added the type: bug Something isn't correct or isn't working label Dec 23, 2023
@dvmorris
Copy link

dvmorris commented May 7, 2024

Did anyone figure out how to resolve this issue?

@hoxbro
Copy link
Member

hoxbro commented May 7, 2024

I can get figures to show by wrapping them in pn.panel:

image

hv.show_versions
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

@hoxbro hoxbro changed the title Widget @bokeh/jupyter_bokeh BokehModel is not supported Empty output in Colab May 7, 2024
@hoxbro hoxbro added this to the 1.19.0 milestone May 18, 2024
@philippjfr
Copy link
Member

So this seems to work:

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.

@hoxbro hoxbro mentioned this issue Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants