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

Panel Matplotlib pane fails when interactive=True #41

Open
Tracked by #91
ncvangilse opened this issue Nov 12, 2021 · 8 comments
Open
Tracked by #91

Panel Matplotlib pane fails when interactive=True #41

ncvangilse opened this issue Nov 12, 2021 · 8 comments

Comments

@ncvangilse
Copy link

I was directed to file an issue here from https://discourse.holoviz.org/t/matplotlib-pane-throwing-attributeerror-when-interactive-true/2911

The minimal app:

import panel as pn
from matplotlib import pyplot as plt

fig, ax = plt.subplots()
ax.plot([0,1,2], [2,2,4])
pn.pane.plot.Matplotlib(fig, interactive=True).show()

works when

    - ipykernel<6  
    - ipympl==0.7.0  
    - panel<=0.12.1  

But I have discovered that even with these versions, the app crashes when the page is reloaded.
If I run it via docker, the panes displays correctly the first time the app spins up, but subsequent sessions will display horizontally squished panes:

Capture

where the first session dies with trace:

HTTPServerRequest(protocol='http', host='localhost:58471', method='GET', uri='/', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\traitlets\traitlets.py", line 537, in get
    value = obj._trait_values[self.name]
KeyError: 'layout'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\tornado\web.py", line 1704, in _execute
    result = await result
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\panel\io\server.py", line 206, in get
    session = await self.get_session()
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\bokeh\server\views\session_handler.py", line 120, in get_session
    session = await self.application_context.create_session_if_needed(session_id, self.request, token)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\bokeh\server\contexts.py", line 218, in create_session_if_needed
    self._application.initialize_document(doc)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\panel\io\server.py", line 172, in initialize_document
    super().initialize_document(doc)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\bokeh\application\application.py", line 171, in initialize_document
    h.modify_document(doc)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\bokeh\application\handlers\function.py", line 132, in modify_document
    self._func(doc)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\panel\io\server.py", line 81, in _eval_panel
    doc = as_panel(panel)._modify_doc(server_id, title, doc, location)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\panel\viewable.py", line 244, in _modify_doc
    return self.server_doc(doc, title, location)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\panel\viewable.py", line 794, in server_doc
    model = self.get_root(doc)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\panel\pane\base.py", line 265, in get_root
    root = self._get_model(doc, comm=comm)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\panel\pane\plot.py", line 192, in _get_model
    manager = self._get_widget(self.object)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\panel\pane\plot.py", line 178, in _get_widget
    canvas = Canvas(fig)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipympl\backend_nbagg.py", line 163, in __init__
    DOMWidget.__init__(self, *args, **kwargs)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipywidgets\widgets\widget.py", line 415, in __init__
    self.open()
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipywidgets\widgets\widget.py", line 428, in open
    state, buffer_paths, buffers = _remove_buffers(self.get_state())
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipywidgets\widgets\widget.py", line 518, in get_state
    value = to_json(getattr(self, k), self)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\traitlets\traitlets.py", line 577, in __get__
    return self.get(obj, cls)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\traitlets\traitlets.py", line 540, in get
    default = obj.trait_defaults(self.name)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\traitlets\traitlets.py", line 1580, in trait_defaults
    return self._get_trait_default_generator(names[0])(self)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\traitlets\traitlets.py", line 513, in default
    return self.make_dynamic_default()
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipywidgets\widgets\trait_types.py", line 168, in make_dynamic_default
    return self.klass(*(self.default_args or ()),
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipywidgets\widgets\widget.py", line 415, in __init__
    self.open()
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipywidgets\widgets\widget.py", line 438, in open
    self.comm = Comm(**args)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipykernel\comm\comm.py", line 57, in __init__
    self.open(data=data, metadata=metadata, buffers=buffers)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipykernel\comm\comm.py", line 91, in open
    self._publish_msg('comm_open',
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipykernel\comm\comm.py", line 66, in _publish_msg
    self.kernel.session.send(self.kernel.iopub_socket, msg_type,
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipywidgets_bokeh\kernel.py", line 80, in send
    self._trigger_change(event)
  File "C:\Users\nchvg\Miniconda3\envs\optisoil-engineering-tools\lib\site-packages\ipywidgets_bokeh\kernel.py", line 103, in _trigger_change
    self.document.callbacks.trigger_on_change(event)
AttributeError: 'Document' object has no attribute 'callbacks'
@philippjfr
Copy link
Contributor

Should have updated the pins but latest ipywidgets_bokeh requires bokeh>2.4.

@MarcSkovMadsen
Copy link

MarcSkovMadsen commented Nov 13, 2021

I tried the example with the latest version

bokeh 2.4.1
ipykernel 6.5.0
ipympl 0.8.2
ipywidgets-bokeh 1.2.1
matplotlib 3.4.3
panel 0.12.4

It now throws another error

import panel as pn
from matplotlib import pyplot as plt

FONTAWESOME_LINK = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.css"
pn.config.css_files.append(FONTAWESOME_LINK)

fig, ax = plt.subplots()
ax.plot([0,1,2], [2,2,4])
pn.pane.plot.Matplotlib(fig, interactive=True).show()
$ python 'snippets\script.py'
Launching server at http://localhost:51985
WARNING:tornado.access:404 GET /favicon.ico (::1) 1.00ms
ERROR:fake:Invalid Message
Traceback (most recent call last):
  File "C:\repos\private\panel-visuals\.venv\lib\site-packages\ipykernel\kernelbase.py", line 312, in dispatch_shell
    msg = self.session.deserialize(msg, content=True, copy=False)
  File "C:\repos\private\panel-visuals\.venv\lib\site-packages\jupyter_client\session.py", line 1048, in deserialize
    raise ValueError("Duplicate Signature: %r" % signature)
ValueError: Duplicate Signature: b'ddb25f037b3c018553a6441f9fd711c54e4c159ba478de1f5ac630117f72a267'      
ERROR:fake:Invalid Message
....
Traceback (most recent call last):
  File "C:\repos\private\panel-visuals\.venv\lib\site-packages\ipykernel\kernelbase.py", line 312, in dispatch_shell
    msg = self.session.deserialize(msg, content=True, copy=False)
  File "C:\repos\private\panel-visuals\.venv\lib\site-packages\jupyter_client\session.py", line 1048, in deserialize
    raise ValueError("Duplicate Signature: %r" % signature)
ValueError: Duplicate Signature: b'400aa479fa9ab6a81aa652cb81b59f1b3e8870a9a863d78014879dd57855b86c'      
ERROR:fake:Invalid Message
Traceback (most recent call last):
  File "C:\repos\private\panel-visuals\.venv\lib\site-packages\ipykernel\kernelbase.py", line 312, in dispatch_shell
    msg = self.session.deserialize(msg, content=True, copy=False)
  File "C:\repos\private\panel-visuals\.venv\lib\site-packages\jupyter_client\session.py", line 1048, in deserialize
    raise ValueError("Duplicate Signature: %r" % signature)
ValueError: Duplicate Signature: b'400aa479fa9ab6a81aa652cb81b59f1b3e8870a9a863d78014879dd57855b86c'      
ERROR:fake:Invalid Message
Traceback (most recent call last):
  File "C:\repos\private\panel-visuals\.venv\lib\site-packages\ipykernel\kernelbase.py", line 312, in dispatch_shell
    msg = self.session.deserialize(msg, content=True, copy=False)
  File "C:\repos\private\panel-visuals\.venv\lib\site-packages\jupyter_client\session.py", line 1048, in deserialize
    raise ValueError("Duplicate Signature: %r" % signature)
ValueError: Duplicate Signature: b'400aa479fa9ab6a81aa652cb81b59f1b3e8870a9a863d78014879dd57855b86c'      
WARNING:tornado.access:404 GET /static/extensions/ipywidgets_bokeh/06c52960c6d2c0312a3e.woff?v=4.7.0 (::1) 1.00ms
WARNING:tornado.access:404 GET /static/extensions/ipywidgets_bokeh/4c6f1cd9993ba8a53b8e.ttf?v=4.7.0 (::1) 
1.00ms

The problem is also there if I downgrade ipykernel to 5.5.6.

@jrklasen
Copy link

Hi, I was wondering if there is any update on this issue?

@philippjfr
Copy link
Contributor

This should be resolved with latest Panel (0.13.0) and bokeh (2.4.2).

@jrklasen
Copy link

I run this with the latest versions of the tools and got inconsistent results. It was not producing reliable results on Mac and Linux, Chrome and Firefox, classic notebook and lab. What seems to work reliably is downgrading ipympl to 0.7.0 and using a classic notebook.

@jrklasen
Copy link

jrklasen commented Apr 26, 2022

sometimes it even altered jupyterlab in weird ways. But this might be related to the "render with panel" button

Screenshot from 2022-04-26 12-59-29

@philippjfr
Copy link
Contributor

That should have been resolved by panel 0.13. can you confirm what panel.__version__ reports?

@jrklasen
Copy link

yes, I can confirm my panel version is '0.13.0'

@ndmlny-qs ndmlny-qs mentioned this issue Apr 6, 2023
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants