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

Sizing mode doesn't take effect until object is set twice in Plotly pane #7445

Open
14lclark opened this issue Oct 25, 2024 · 0 comments
Open

Comments

@14lclark
Copy link

ALL software version info

Software Version Info
Panel 1.5.3 (but also tested on 1.4.5)
Plotly 5.24.1 (but also tested on 5.23.0)
Firefox 131.0.3 
Ubuntu 24.04.1

Description of expected behavior and the observed behavior

Initialize a Plotly pane with no object, sizing mode of 'stretch_width', and use a viewport update policy (specifically 'throttle' in my case). In another location, change the visibility to True and update the object to a specific Plotly plot.

What should happen: the new plot appears and stretches to the width of the container it's located in.
What is observed to happen: the new plot appears as some default width, and does not stretch to the width of the container.

To work around this, I noticed that setting the object again will then cause the sizing mode to take effect. Specifically, I would set self.plot.object = self.plot.object, and the size will update appropriately.

To see this, in the example below uncomment the final line in the method "update_plot2".

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

import panel as pn
import plotly.express as px

pn.extension("plotly")

class UI:
    def __init__(self) -> None:
        self.flt = pn.template.FastListTemplate(
            site="Example",
            title="Example",
            main_layout=None,
            sidebar=[],
            main=[]
        )
        self.plot1 = pn.pane.Plotly(
            visible=False, sizing_mode="stretch_width"
        )

        self.plot2 = pn.pane.Plotly(
            visible=False, sizing_mode="stretch_width",
            viewport_update_policy='throttle', viewport_update_throttle=250
        )

        self.plot3 = pn.pane.Plotly(
            visible=True, sizing_mode="stretch_width",
            viewport_update_policy='throttle', viewport_update_throttle=250
        )

        self.update_plot1_button = pn.widgets.Button(
            name="Update object in plot1",
            on_click=self.update_plot1
        )

        self.update_plot2_button = pn.widgets.Button(
            name="Update object in plot2",
            on_click=self.update_plot2
        )

        self.update_plot3_button = pn.widgets.Button(
            name="Update object in plot3",
            on_click=self.update_plot3
        )

    def update_plot1(self, _):
        self.plot1.visible = True
        self.plot1.object = px.timeline(x_start=[], x_end=[])

    def update_plot2(self, _):
        self.plot2.visible = True
        self.plot2.object = px.timeline(x_start=[], x_end=[])
        # self.plot2.object = self.plot2.object

    def update_plot3(self, _):
        self.plot3.visible = True
        self.plot3.object = px.timeline(x_start=[], x_end=[])


def make_example():
    ui = UI()
    ui.flt.main += [
        pn.Accordion(
            ("Plot 1, visible=False, no viewport policy", ui.plot1),
            ("Plot 2, visible=False, throttle policy", ui.plot2),
            ("Plot 3, visible=True, throttle policy", ui.plot3),
            active=[0, 1, 2]
        )
    ]
    ui.flt.sidebar += [
        ui.update_plot1_button,
        ui.update_plot2_button,
        ui.update_plot3_button
    ]
    return ui.flt.servable()

example = make_example()
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

1 participant