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

Cannot render image in vs code #1111

Closed
droumis opened this issue Jul 17, 2023 · 3 comments
Closed

Cannot render image in vs code #1111

droumis opened this issue Jul 17, 2023 · 3 comments
Labels

Comments

@droumis
Copy link
Member

droumis commented Jul 17, 2023

ALL software version info

Python : 3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:38:11)
[Clang 14.0.6 ]
Operating system : macOS-13.4.1-arm64-arm-64bit
holoviews : 1.16.2

IPython : 8.14.0
bokeh : 3.2.0
colorcet : 3.0.1
cudf : -
dask : 2023.7.0
datashader : 0.15.1
geoviews : -
hvplot : 0.8.4
ibis : -
jupyter_bokeh : 2.0.4
jupyterlab : 4.0.2
matplotlib : 3.7.2
networkx : 3.1
notebook : 6.5.4
numba : 0.57.1
numpy : 1.24.4
pandas : 1.5.3
panel : 1.2.0
param : 1.13.0
pillow : -
plotly : -
pyarrow : 12.0.1
scipy : 1.11.1
skimage : 0.21.0
spatialpandas : -
streamz : -
xarray : 2023.6.0

Description of expected behavior and the observed behavior

hvPlot in vscode notebook produces error below. No error with Jupyter lab.

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

import numpy as np
import xarray as xr
import hvplot.xarray

x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
z = np.linspace(-5, 5, 100)
xx, yy, zz = np.meshgrid(x, y, z)
values = np.sin(xx) ** 10 + np.cos(10 + yy * xx) * np.cos(xx)

da = xr.DataArray(values, coords=[x, y, z], dims=["x", "y", "z"])

da.hvplot.image() # works in nb, doesn't work in vscode

# but a line plot works fine in both environments:

import pandas as pd
import hvplot.pandas

line_values = da.sel(y=y[0], z=z[0])
df_line = pd.DataFrame({'values': line_values.values, 'x': line_values.x})
df_line.hvplot('x', 'values')

Stack traceback and/or browser JavaScript console output

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/IPython/core/formatters.py:974](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/IPython/core/formatters.py:974), in MimeBundleFormatter.__call__(self, obj, include, exclude)
    971     method = get_real_method(obj, self.print_method)
    973     if method is not None:
--> 974         return method(include=include, exclude=exclude)
    975     return None
    976 else:

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/core/dimension.py:1290](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/core/dimension.py:1290), in Dimensioned._repr_mimebundle_(self, include, exclude)
   1283 def _repr_mimebundle_(self, include=None, exclude=None):
   1284     """
   1285     Resolves the class hierarchy for the class rendering the
   1286     object using any display hooks registered on Store.display
   1287     hooks.  The output of all registered display_hooks is then
   1288     combined and returned.
   1289     """
-> 1290     return Store.render(self)

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/core/options.py:1425](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/core/options.py:1425), in Store.render(cls, obj)
   1423 data, metadata = {}, {}
   1424 for hook in hooks:
-> 1425     ret = hook(obj)
   1426     if ret is None:
   1427         continue

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:280](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:280), in pprint_display(obj)
    278 if not ip.display_formatter.formatters['text/plain'].pprint:
    279     return None
--> 280 return display(obj, raw_output=True)

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:254](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:254), in display(obj, raw_output, **kwargs)
    252 elif isinstance(obj, (HoloMap, DynamicMap)):
    253     with option_state(obj):
--> 254         output = map_display(obj)
    255 elif isinstance(obj, Plot):
    256     output = render(obj)

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:142](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:142), in display_hook..wrapped(element)
    140 try:
    141     max_frames = OutputSettings.options['max_frames']
--> 142     mimebundle = fn(element, max_frames=max_frames)
    143     if mimebundle is None:
    144         return {}, {}

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:202](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:202), in map_display(vmap, max_frames)
    199     max_frame_warning(max_frames)
    200     return None
--> 202 return render(vmap)

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:69](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py:69), in render(obj, **kwargs)
     66 if renderer.fig == 'pdf':
     67     renderer = renderer.instance(fig='png')
---> 69 return renderer.components(obj, **kwargs)

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/plotting/renderer.py:400](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/plotting/renderer.py:400), in Renderer.components(self, obj, fmt, comm, **kwargs)
    398 if embed or config.comms == 'default':
    399     return self._render_panel(plot, embed, comm)
--> 400 return self._render_ipywidget(plot)

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/plotting/renderer.py:421](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/holoviews/plotting/renderer.py:421), in Renderer._render_ipywidget(self, plot)
    419 def _render_ipywidget(self, plot):
    420     # Handle rendering object as ipywidget
--> 421     widget = ipywidget(plot, combine_events=True)
    422     if hasattr(widget, '_repr_mimebundle_'):
    423         return widget._repr_mimebundle_(), {}

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/panel/io/notebook.py:516](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/panel/io/notebook.py:516), in ipywidget(obj, doc, **kwargs)
    514 doc = doc if doc else Document()
    515 model = panel(obj, **kwargs).get_root(doc=doc)
--> 516 widget = BokehModel(model, combine_events=True)
    517 if hasattr(widget, '_view_count'):
    518     widget._view_count = 0

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/jupyter_bokeh/widgets.py:68](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/jupyter_bokeh/widgets.py:68), in BokehModel.__init__(self, model, **kwargs)
     66 def __init__(self, model, **kwargs):
     67     assert isinstance(model, LayoutDOM)
---> 68     self.update_from_model(model)
     69     super(BokehModel, self).__init__(**kwargs)
     70     self.on_msg(self._sync_model)

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/jupyter_bokeh/widgets.py:91](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/jupyter_bokeh/widgets.py:91), in BokehModel.update_from_model(self, model)
     89 def update_from_model(self, model):
     90     self._model = model
---> 91     self.render_bundle = self._model_to_traits(model)
     92     self._document.on_change_dispatch_to(self)

File [~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/jupyter_bokeh/widgets.py:81](https://file+.vscode-resource.vscode-cdn.net/Users/droumis/src/neuro/workflows/video-viewer/dev/~/opt/miniconda3/envs/neuro-video-viewer/lib/python3.9/site-packages/jupyter_bokeh/widgets.py:81), in BokehModel._model_to_traits(cls, model)
     79     document = Document()
     80     document.add_root(model)
---> 81 (docs_json, [render_item]) = standalone_docs_json_and_render_items([model], True)
     82 render_bundle = dict(
     83     docs_json=docs_json,
     84     render_items=[render_item.to_json()],
     85     div=div_for_render_item(render_item),
     86 )
     87 return render_bundle

TypeError: standalone_docs_json_and_render_items() takes 1 positional argument but 2 were given

Screenshots or screencasts of the bug in action

@droumis droumis added the TRIAGE label Jul 17, 2023
@droumis droumis changed the title hvPlot cannot render image in vs code Cannot render image in vs code Jul 17, 2023
@hoxbro
Copy link
Member

hoxbro commented Jul 18, 2023

This is because jupyter_bokeh does not work with jupyterlab 4. Try downgrade jupyterlab<4 and upgrade jupyter_bokeh=3.0.7.

@droumis droumis closed this as completed Jul 18, 2023
@philippjfr
Copy link
Member

Hmm, maybe I'm stupid but what does VSCode rendering have to do with Jlab 4?

@hoxbro
Copy link
Member

hoxbro commented Jul 18, 2023

The latest jupyter_bokeh released does not work with jupyterlab 4 and has it pinned. So if you have jupyterlab 4 installed and then install jupyter_bokeh it will install 2.0.4, which does not have the pin.

This conda create -n tmp55 jupyterlab=4 jupyter_bokeh -c conda-forge --dry-run | grep jupyter will return this:

    - jupyter_bokeh
    - jupyterlab=4
    jupyter_bokeh-2.0.4        |     pyhd8ed1ab_0         1.6 MB  conda-forge
  jupyter-lsp        conda-forge/noarch::jupyter-lsp-2.2.0-pyhd8ed1ab_0 
  jupyter_bokeh      conda-forge/noarch::jupyter_bokeh-2.0.4-pyhd8ed1ab_0 
  jupyter_client     conda-forge/noarch::jupyter_client-8.3.0-pyhd8ed1ab_0 
  jupyter_core       conda-forge/linux-64::jupyter_core-5.3.1-py311h38be061_0 
  jupyter_events     conda-forge/noarch::jupyter_events-0.6.3-pyhd8ed1ab_0 
  jupyter_server     conda-forge/noarch::jupyter_server-2.7.0-pyhd8ed1ab_0 
  jupyter_server_te~ conda-forge/noarch::jupyter_server_terminals-0.4.4-pyhd8ed1ab_1 
  jupyterlab         conda-forge/noarch::jupyterlab-4.0.3-pyhd8ed1ab_0 
  jupyterlab_pygmen~ conda-forge/noarch::jupyterlab_pygments-0.2.2-pyhd8ed1ab_0 
  jupyterlab_server  conda-forge/noarch::jupyterlab_server-2.23.0-pyhd8ed1ab_0 
  jupyterlab_widgets conda-forge/noarch::jupyterlab_widgets-3.0.8-pyhd8ed1ab_0 

Edit: This is the related issue bokeh/jupyter_bokeh#195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants