bokeh / jupyter_bokeh

An extension for rendering Bokeh content in JupyterLab notebooks
BSD 3-Clause "New" or "Revised" License
249 stars 48 forks source link

Error while running notebooks in VS Code #194

Open alexgleith opened 1 year ago

alexgleith commented 1 year ago

If I run a simple example like the below in VS Code:

import numpy as np
import holoviews as hv

def sine_curve(phase, freq):
    xvals = [0.1* i for i in range(100)]
    return hv.Curve((xvals, [np.sin(phase+freq*x) for x in xvals]))

# When run live, this cell's output should match the behavior of the GIF below
dmap = hv.DynamicMap(sine_curve, kdims=['phase', 'frequency'])
dmap.redim.range(phase=(0.5,1), frequency=(0.5,1.25))

I get the error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File [/opt/homebrew/lib/python3.11/site-packages/jupyter_bokeh/widgets.py:133](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/jupyter_bokeh/widgets.py:133), in BokehModel._sync_model(self, _, content, _buffers)
    131         cb(attr, old, new)
    132 elif kind == 'MessageSent':
--> 133     self._document.apply_json_event(content["msg_data"])

AttributeError: 'Document' object has no attribute 'apply_json_event'

Libraries I have installed include:

VS Code is: 1.78.2 running on a M1 mac.

Also note that if I run the same example in Jupyter Lab on the same machine it renders fine, but seems to not have interactivity.

image
mattpap commented 1 year ago

bokeh==2.4.3 jupyter-bokeh==2.0.4

It looks like jupyter-bokeh compatible with bokeh 2.4 was never published. The last working version is probably bokeh 2.3. Note that holoviz stack based on bokeh 3 was published yesterday, so if you don't mind updating your dependencies, then this may be a non-issue for you. We probably will want to make a retroactive 2.0.5 release anyway.

alexgleith commented 1 year ago

I have a working local environment now. It was pretty hard to work out what needed to change, but this combination is ok:

bokeh==2.4.3
jupyter-bokeh==3.0.5

Can render in VS Code now, although I can't work out if I need to execute this or not: hv.extension('bokeh')

bryevdv commented 1 year ago

although I can't work out if I need to execute this or not: hv.extension('bokeh')

Holoviews is a separate project, that's really a question for them: https://discourse.holoviz.org but there may also be useful information here: https://github.com/bokeh/bokeh/issues/10765

TLDR; Microsoft does not use standard websockets and that's an issue