Stretch width doesn't seem to be honored by pn.Column and pn.Row

The docs show:

    pn.pane.Str(background='#f0f0f0', height=100, sizing_mode='stretch_width'),
    width_policy='max', height=200

That works, but what if I don’t want to have a pn.pane inside of the pn.Row? It seems like I should be able to simplify this down to something like:
pn.Row('Foo:',sizing_mode='stretch_width', width_policy='max', background='WhiteSmoke')
pn.Column('Foo:', sizing_mode='stretch_width', width_policy='max', background='WhiteSmoke')
but this doesn’t appear to work.

What am I missing?

If you pass a string to pn.Row it creates a pane which does not have sizing_mode passed to it. The pane can then be stretched afterwards, but this remove the elegance of what you are trying to do.

import panel as pn

a = pn.Row('Foo:',sizing_mode='stretch_width', width_policy='max', background='WhiteSmoke')
a[0].sizing_mode = 'stretch_width'

Alternative you can change Row to panel like this: pn.panel('Foo:',sizing_mode='stretch_width', width_policy='max', background='WhiteSmoke')

1 Like

aha! I figured it had to do with panes somehow. I think it should warn when I pass it something that its going to get ignored. It would be good if the docs page had this info too.

Thank you!!

Please note you can change the default sizing_mode globally. I almost always do that.

1 Like