holoviz / panel

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

Nested plotly tabs produce AttributeError #2459

Closed thomasbangels closed 3 years ago

thomasbangels commented 3 years ago

Thanks to #2418, plotly figures have the desired interactivity when displayed in tabs. However, when the plotly figures are inside nested tabs, the following AttributeError is triggered:

Traceback (most recent call last):
  File "panel_bug_report_nested_tabs.py", line 27, in <module>
    plots.save("nested_tabs_depth_2.html", resources="inline")
  File "/home/bangels/.local/lib/python3.8/site-packages/panel/viewable.py", line 766, in save
    return save(self, filename, title, resources, template,
  File "/home/bangels/.local/lib/python3.8/site-packages/panel/io/save.py", line 210, in save
    model = panel.get_root(doc, comm)
  File "/home/bangels/.local/lib/python3.8/site-packages/panel/viewable.py", line 514, in get_root
    self._preprocess(root)
  File "/home/bangels/.local/lib/python3.8/site-packages/panel/viewable.py", line 448, in _preprocess
    hook(self, root)
  File "/home/bangels/.local/lib/python3.8/site-packages/panel/pane/plotly.py", line 338, in _patch_tabs_plotly
    if not any(tabs.select_one(pt) for pt in parent_tabs if pt is not tabs):
  File "/home/bangels/.local/lib/python3.8/site-packages/panel/pane/plotly.py", line 338, in <genexpr>
    if not any(tabs.select_one(pt) for pt in parent_tabs if pt is not tabs):
  File "/home/bangels/.local/lib/python3.8/site-packages/bokeh/model.py", line 584, in select_one
    result = list(self.select(selector))
  File "/home/bangels/.local/lib/python3.8/site-packages/bokeh/core/query.py", line 88, in <genexpr>
    return (obj for obj in objs if match(obj, selector, context))
  File "/home/bangels/.local/lib/python3.8/site-packages/bokeh/core/query.py", line 160, in match
    for key, val in selector.items():
AttributeError: 'Tabs' object has no attribute 'items'

Code snippet to produce the error:

import numpy as np
import panel as pn
import plotly.graph_objects as go

pn.extension('plotly')

plots = pn.Tabs(tabs_location="left")
plots_normal = pn.Tabs(tabs_location="left")
plots_inverse = pn.Tabs(tabs_location="left")
plots.append(("normal", plots_normal))
plots.append(("inverse", plots_inverse))

x = np.arange(10)
pn1 = go.Scatter(x=x, y=x**2, marker={"color": "red"})
pn2 = go.Scatter(x=x, y=x**3, marker={"color": "green"})
pi1 = go.Scatter(x=x**2, y=x, marker={"color": "blue"})
pi2 = go.Scatter(x=x**3, y=x, marker={"color": "black"})
plots_normal.append(("quadratic", pn1))
plots_normal.append(("third power", pn2))
plots_inverse.append(("quadratic", pi1))
plots_inverse.append(("third power", pi2))

# no nested tabs, works
plots_normal.save("nested_tabs_depth_1.html", resources="inline")

# nested tabs, gives 'items' attribute error with bokeh Tabs
plots.save("nested_tabs_depth_2.html", resources="inline")

Version info:

panel   0.12.0a22 
bokeh   2.3.2
param   1.10.1    
plotly  4.9.0
python  3.8.5
OS      Ubuntu 20.04
philippjfr commented 3 years ago

Thanks for catching this.