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

Update Multiple Tabs with plotly panes #2747

Closed
devhello145 opened this issue Sep 17, 2021 · 1 comment · Fixed by #2777
Closed

Update Multiple Tabs with plotly panes #2747

devhello145 opened this issue Sep 17, 2021 · 1 comment · Fixed by #2777
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@devhello145
Copy link

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc)

os: Windows
python: 3.8
browser: firefox 92.0
panel: 0.12.1 (0.12.2 have another bug)

pip freeze

addict==2.4.0
argon2-cffi==21.1.0
attrs==21.2.0
backcall==0.2.0
bleach==4.1.0
bokeh==2.3.3
certifi==2021.5.30
cffi==1.14.6
charset-normalizer==2.0.5
colorama==0.4.4
cycler==0.10.0
debugpy==1.4.3
decorator==5.1.0
deepdiff==5.5.0
defusedxml==0.7.1
entrypoints==0.3
future==0.18.2
h5py==3.4.0
idna==3.2
ipykernel==6.4.1
ipympl==0.7.0
ipython==7.27.0
ipython-genutils==0.2.0
ipywidgets==7.6.5
ipywidgets-bokeh==1.0.2
jedi==0.18.0
Jinja2==3.0.1
jsonschema==3.2.0
jupyter-client==7.0.3
jupyter-core==4.8.1
jupyterlab-pygments==0.1.2
jupyterlab-widgets==1.0.2
kaleido==0.2.1
kiwisolver==1.3.2
Markdown==3.3.4
MarkupSafe==2.0.1
matplotlib==3.4.3
matplotlib-inline==0.1.3
mistune==0.8.4
nbclient==0.5.4
nbconvert==6.1.0
nbformat==5.1.3
nest-asyncio==1.5.1
notebook==6.4.4
numpy==1.21.2
ordered-set==4.0.2
packaging==21.0
pandas==1.3.3
pandocfilters==1.5.0
panel==0.12.1
param==1.11.1
parse==1.19.0
parso==0.8.2
pickleshare==0.7.5
Pillow==8.3.2
plotly==5.1.0
pretty-html-table==0.9.11
prometheus-client==0.11.0
prompt-toolkit==3.0.20
pycparser==2.20
pyct==0.4.8
Pygments==2.10.0
pymatreader==0.0.25
pyparsing==2.4.7
pyrsistent==0.18.0
python-dateutil==2.8.2
pytz==2021.1
pyviz-comms==2.1.0
pywin32==301
pywinpty==1.1.4
PyYAML==5.4.1
pyzmq==22.3.0
requests==2.26.0
scipy==1.7.1
seaborn==0.11.2
Send2Trash==1.8.0
six==1.16.0
tenacity==8.0.1
terminado==0.12.1
testpath==0.5.0
tornado==6.1
tqdm==4.62.2
traitlets==5.1.0
typing-extensions==3.10.0.2
urllib3==1.26.6
wcwidth==0.2.5
webencodings==0.5.1
widgetsnbextension==3.5.1
xmltodict==0.12.0

Description of expected behavior and the observed behavior

Bug: When we update one tab with plotly plots, plotly plots disappeare on another tabs.

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

import numpy as np
import panel as pn
import panel.widgets as pnw
import param as pm

import plotly.graph_objects as go


class Settings(pm.Parameterized):
    n = pm.Integer(default=2)
    update = pm.Event("Update plots")

settings = Settings()


class Plots(pm.Parameterized):

    SETTINGS=pm.Parameter()
    update_view = pm.Event()

    def __init__(self):
        self.SETTINGS = settings
        super().__init__()

        self.panes = []
        self.figs = []
        self.set_n()

    @staticmethod
    def _get_data():
        N = 10
        return dict(x=np.arange(N), y=np.random.rand(N))

    def _create(self):
        fig = go.Figure().to_dict()
        fig["data"].append(
            dict(**self._get_data(), type="scatter")
        )
        pane = pn.pane.Plotly(fig)
        return fig, pane

    @pm.depends("SETTINGS.n", watch=True)
    def set_n(self):
        old_n = len(self.panes)
        new_n = self.SETTINGS.n
        diff = new_n - old_n

        if diff > 0:
            for _ in range(diff):
                fig, pane = self._create()
                self.panes.append(pane)
                self.figs.append(fig)
        elif diff < 0:
            self.panes = self.panes[:new_n]
            self.figs = self.figs[:new_n]
        else:
            return
        self.param.trigger("update_view")

    @pm.depends("SETTINGS.update", watch=True)
    def update(self):
        for pane, fig in zip(self.panes, self.figs):
            fig["data"][0].update(self._get_data())
            pane.object = fig
        self.param.trigger("update_view")

    @pm.depends("update_view")
    def view(self):
        layout = []
        for i, pane in enumerate(self.panes):
            ## option 1
            # layout.append(pane)
            
            ## option 2
            # layout.append(pn.Card(pane, header=str(i)))
            
            ## option 3
            ## console error: Uncaught ReferenceError: model is not defined
            # layout.append(pn.WidgetBox(f"### {i}", pane))

            ## option 4
            ## same error as in option 3
            layout.append(pn.Column(f"### {i}", pane))
        return pn.Column(*layout)


plots1 = Plots()
plots2 = Plots()
        
app = pn.template.VanillaTemplate(title="Test")
app.sidebar.append(pn.Param(settings))

app.main.append(pn.Tabs(plots1.view, plots2.view))


pn.serve(app)

Stack traceback and/or browser JavaScript console output

image

Screenshots or screencasts of the bug in actio

panel_0.12.1_.mp4

Please suggest any fast solution if it's possible

@devhello145
Copy link
Author

Also same bug for panel v0.12.2

@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Sep 21, 2021
@philippjfr philippjfr added this to the v0.12.4 milestone Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants