holoviz / panel

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

A bound function does not resize its container when rerunning. #3346

Open MarcSkovMadsen opened 2 years ago

MarcSkovMadsen commented 2 years ago

I would expect the below to resize its container. But the height stays fixed, end ends up overflowing the card.

https://user-images.githubusercontent.com/42288570/162560111-cd2df69a-7c91-4a26-8a52-368bdf4c9d0b.mp4

import panel as pn

pn.extension(sizing_mode="stretch_width", template="fast")

logo_url= "https://pydata.org/wp-content/uploads/2019/06/pydata-logo-final.png"
ACCENT = "orange"

pn.pane.PNG(logo_url, embed=True, height=500, sizing_mode="scale_width").servable(area="sidebar")

def model(count=5):
    return "# Hello PyData World\n"*count

slider = pn.widgets.IntSlider(value=5, start=0, end=10, name="count").servable(area="sidebar")
imodel = pn.bind(model, count=slider)
pn.panel(imodel, sizing_mode="stretch_both").servable()

pn.state.template.param.update(site="PyData Cph 2022", title="Introduction to Data Apps with Panel")
MarcSkovMadsen commented 2 years ago

Hacky Workaround

I can trigger a resize by temporarily changing the sizing_mode.

https://user-images.githubusercontent.com/42288570/173222947-9b6c4257-b5d2-4e69-b5b5-4736739f7015.mp4

import panel as pn

pn.extension(sizing_mode="stretch_width", template="fast")

logo_url= "https://pydata.org/wp-content/uploads/2019/06/pydata-logo-final.png"
ACCENT = "orange"

pn.pane.PNG(logo_url, embed=True, height=500, sizing_mode="scale_width").servable(area="sidebar")

def model(count=5):
    return "# Hello PyData World\n"*count

slider = pn.widgets.IntSlider(value=5, start=0, end=10, name="count").servable(area="sidebar")
imodel = pn.bind(model, count=slider)
model_panel = pn.panel(imodel, sizing_mode="stretch_both").servable()

@pn.depends(slider, watch=True)
def hacky_workaround(slider):
  model_panel.sizing_mode="fixed"
  model_panel.sizing_mode="stretch_both"

pn.state.template.param.update(site="PyData Cph 2022", title="Introduction to Data Apps with Panel")

Comment

I believe a bug like this is REALLY, REALLY important to fix as it is bugs like these that make @pn.depends/@pn.bind not nearly as powerful as they should be and having users spend so much more time on fixing layout issues than they have to with competing frameworks.