Panel dynamic tab crashes

I have a panel/bokeh server application embedded in a Flask/gunicorn server, and it works well.

The issue I am currently trying to address is slow-ish startup times of a client session when used on a high-dimensional problem, which, by extension, means many plots and widgets in the interactive web page.

One approach I have investigated to lessen the startup time is to set the dynamic property of the panel Tabs equal to True, i.e.

pn.Tabs(..., dynamic=True)

In so doing, the application crashes with the resulting stack trace below. I am running with bokeh 2.0.2 and panel 0.9.5.

Traceback (most recent call last):
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/tornado/web.py", line 1703, in _execute
    result = await result
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/bokeh/server/views/autoload_js_handler.py", line 60, in get
    session = await self.get_session()
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/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 "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/bokeh/server/contexts.py", line 218, in create_session_if_needed
    self._application.initialize_document(doc)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/bokeh/application/application.py", line 171, in initialize_document
    h.modify_document(doc)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/bokeh/application/handlers/function.py", line 132, in modify_document
    self._func(doc)
  File "/Users/x/Desktop/x/x_server.py", line 306, in bk_app
    w_per_ui=_w_per_ui, num_col=_num_col)
  File "/Users/x/Desktop/x/session/session.py", line 230, in go
    pn.Column(*_ll).server_doc(D)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/panel/viewable.py", line 706, in server_doc
    model = self.get_root(doc)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/panel/viewable.py", line 643, in get_root
    self._preprocess(root)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/panel/viewable.py", line 410, in _preprocess
    hook(self, root)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/panel/links.py", line 87, in _process_callbacks
    linkable = root_view.select(Viewable)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/panel/layout.py", line 148, in select
    objects += obj.select(selector)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/panel/layout.py", line 148, in select
    objects += obj.select(selector)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/panel/layout.py", line 148, in select
    objects += obj.select(selector)
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/bokeh/core/query.py", line 88, in <genexpr>
    return (obj for obj in objs if match(obj, selector, context))
  File "/Users/x/opt/anaconda3/envs/x/lib/python3.7/site-packages/bokeh/core/query.py", line 160, in match
    for key, val in selector.items():
AttributeError: type object 'Viewable' has no attribute 'items'

Hi @_jm

Would it be possible for you to test if it crashes with Panel 0.9.7 and Bokeh 2.1.1?

And if it does to create some kind of minimal code example and post it

  • here if you believe it’s just a matter of changing your implementation
  • on Github if you believe there is a bug in Panel/ Bokeh.

Thanks.

@Marc

Unfortunately, my program does not work with bokeh 2.1.1. There is a regression in the bokeh interpolator that requires me to use 2.0.2. See bokeh github issue 10320.

That regression is supposed to be fixed in the next release of bokeh, 2.2.0. I will see if the problem here persists with that version and try to pare down my code to a minimal example if so.

Thanks

Hi @_jm

Would the minimal code example need the code that cause the bokeh github issue 10320 in order to reproduce this error?

If not could you try creating that minimal code example and test it on latest versions of Panel and Bokeh?

@Marc

Probably not, but uncertain.

I currently do not know what part of my complex layout and things within that layout cause the crash. I do know that modifying the panel Tabs example in the document to use the dynamic=True property works. So I need to build-up from that example to isolate the root cause.

Here is a minimal example that cause the crash. The key piece seems to be using panel Columns as the viewable items in panel Tabs. I use bokeh Divs and figures to assemble the Columns, but not sure that the crash is specific to those model types.

Version Info:
python: 3.7.7
bokeh: 2.1.1
panel: 0.9.7

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
"""
import numpy as np
import panel as pn

from bokeh.models import ColumnDataSource, Div
from bokeh.plotting import figure

x = np.linspace(0.0, 1.0, 1001)
y1 = np.sin(2.0*np.pi*x)
y2 = np.sin(4.0*np.pi*x)

data = dict(x=x, y1=y1, y2=y2)
source = ColumnDataSource(data=data)

p1 = figure(width=400, height=300)
p1.line(x='x', y='y1', source=source)

p2 = figure(width=400, height=300)
p2.line(x='x', y='y2', source=source)

d1 = Div(text='Sensor A')
d2 = Div(text='Sensor B')

col1 = pn.Column(objects=[d1, p1])
col2 = pn.Column(objects=[d2, p2])

items = [('Group 1', col1), ('Group 2', col2)]
pn.Tabs(*items, dynamic=True).servable()

The problem here was this:

col1 = pn.Column(objects=[d1, p1])
col2 = pn.Column(objects=[d2, p2])

Panel expects the items to be passed as positional arguments not as keyword argument. This meant that the items were not being processed correctly. I’ll make sure to fix that, but you can fix it easily in your code with:

col1 = pn.Column(d1, p1)
col2 = pn.Column(d2, p2)
1 Like

Fixed here: https://github.com/holoviz/panel/pull/1502

Thanks for the prompt reply with a workaround and the follow-up fix!