holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.84k stars 520 forks source link

importing holoviews breaks the ability to embed a bokeh server within a jupyter notebook #3255

Closed kushalkolar closed 2 years ago

kushalkolar commented 2 years ago

It's possible to embed an interactive bokeh server app within a notebook, however just importing holoviews breaks this ability. I am actually not using holoviews but it is imported by another package that I am using. Re-importing bokeh stuff after the holoviews import does not fix the issue.

I'm not sure if I'm supposed to embed a bokeh server differently if holoviews is imported to get around this issue.

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc)

Python version      :  3.8.12 (default, Feb 25 2022, 17:06:02) 
IPython version     :  8.1.1
Tornado version     :  6.1
Bokeh version       :  2.4.2
BokehJS static path :  /home/kushal/python-venvs/mesmerize-napari/lib/python3.8/site-packages/bokeh/server/static
node.js version     :  (not installed)
npm version         :  (not installed)
Operating system    :  Linux-5.10.0-12-amd64-x86_64-with-glibc2.33

holoviews version

'1.14.8'

jupyterlab version:

Version 3.3.0

Browser:

Version 99.0.4844.51 (Official Build) built on Debian 11.2, running on Debian 11.2 (64-bit)

Description of expected behavior and the observed behavior

Expected: Embedding the bokeh server should work.

Complete, minimal, self-contained example code that reproduces the issue

import numpy as np
from bokeh.layouts import column
from bokeh.plotting import figure
from bokeh.models import Slider
from bokeh.io import show, output_notebook

# this import prevent bokeh server from being embedded in jupyter
import holoviews as hv

output_notebook()

def bkapp(doc):
    p = figure(plot_height=512, plot_width=512)#, output_backend='webgl')
    p.grid.grid_line_width = 0
    g = p.image([np.random.rand(512, 512)], x=0, y=0, dw=20, dh=20, level="image")

    def update(attr, old, val):
        g.data_source.data['image'] = [np.random.rand(512, 512)]

    s = Slider(start=0, end=100, value=1, step=1, title="index")
    s.on_change('value', update)
    doc.add_root(column(p, s))

show(bkapp, notebook_url="http://localhost:8888")

Stack traceback and/or browser JavaScript console output

This is the output when holoviews is imported:

ERROR:tornado.application:Uncaught exception GET /autoload.js?bokeh-autoload-element=1235&bokeh-absolute-url=http://localhost:46847&resources=none/ (::1)
HTTPServerRequest(protocol='http', host='localhost:46847', method='GET', uri='/autoload.js?bokeh-autoload-element=1235&bokeh-absolute-url=http://localhost:46847&resources=none/', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
  File "/home/kushal/python-venvs/mesmerize-napari/lib/python3.8/site-packages/tornado/web.py", line 1704, in _execute
    result = await result
  File "/home/kushal/python-venvs/mesmerize-napari/lib/python3.8/site-packages/panel/io/server.py", line 250, in get
    with self._session_prefix():
  File "/usr/local/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/home/kushal/python-venvs/mesmerize-napari/lib/python3.8/site-packages/panel/io/server.py", line 196, in _session_prefix
    rel_path = abs_url.replace(app_path, '')
TypeError: replace() argument 1 must be str, not None
ERROR:tornado.application:Uncaught exception GET /autoload.js?bokeh-autoload-element=1235&bokeh-absolute-url=http://localhost:46847&resources=none/ (::1)
HTTPServerRequest(protocol='http', host='localhost:46847', method='GET', uri='/autoload.js?bokeh-autoload-element=1235&bokeh-absolute-url=http://localhost:46847&resources=none/', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
  File "/home/kushal/python-venvs/mesmerize-napari/lib/python3.8/site-packages/tornado/web.py", line 1704, in _execute
    result = await result
  File "/home/kushal/python-venvs/mesmerize-napari/lib/python3.8/site-packages/panel/io/server.py", line 250, in get
    with self._session_prefix():
  File "/usr/local/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/home/kushal/python-venvs/mesmerize-napari/lib/python3.8/site-packages/panel/io/server.py", line 196, in _session_prefix
    rel_path = abs_url.replace(app_path, '')
TypeError: replace() argument 1 must be str, not None
ERROR:tornado.access:500 GET /autoload.js?bokeh-autoload-element=1235&bokeh-absolute-url=http://localhost:46847&resources=none/ (::1) 8.55ms
ERROR:tornado.access:500 GET /autoload.js?bokeh-autoload-element=1235&bokeh-absolute-url=http://localhost:46847&resources=none/ (::1) 8.55ms

Screenshots or screencasts of the bug in action

https://user-images.githubusercontent.com/9403332/159580101-c789dba6-c2c8-47e4-a846-b7b724d45e34.mp4

philippjfr commented 2 years ago

This was actually a Panel bug, but it looks like it has been resolved already with current dev releases so this will be fixed as soon as Panel 0.13.0 is released.

kushalkolar commented 2 years ago

Thanks! I can confirm that installing the latest pre-release of panel fixes this issue!

pip install panel==0.13.0a45