Panel: Enable setting the panel.Param name manually.

Created on 11 May 2020  路  3Comments  路  Source: holoviz/panel

My Pain

Sometimes I have a param.Parameterized class with a lot of parameters. For layout reasons I might split them up into multiple panel.Params. I would like to give these seperate names.

As far as I can see this is not supported by panel.Param.

Example

As you can see the name is MyComponent instead of the custom one specified.

image

import param
import panel as pn

class MyComponent(param.Parameterized):
    selection1 = param.ObjectSelector()
    selection2 = param.ObjectSelector()

component = MyComponent()
app = pn.Column(
    pn.Param(component, parameters=["selection1"], name="Primary Selections"),
    pn.Param(component, parameters=["selection2"], name="Secondary Selections"),
)
app.show()

Solution

Support this.

Workaround

As you can see below the layout is not nice. There is too much space (margin I guess) between things.

image

import param
import panel as pn

class MyComponent(param.Parameterized):
    selection1 = param.ObjectSelector()
    selection2 = param.ObjectSelector()

component = MyComponent()
app = pn.Column(
    pn.pane.Markdown("# Primary Selections"),
    pn.Param(component, parameters=["selection1"], show_name=False),
    pn.pane.Markdown("# Secondary Selections"),
    pn.Param(component, parameters=["selection2"], show_name=False),
)
app.show()
TRIAGE

All 3 comments

It makes sense to support that I guess, I also encountered the same issue and used a similar workaround. I could give it a try since I've been working on param.py lately.

@philippjfr Does it make sense to you if I explicitly add a name parameter to panel.Param ?

It could be:

  • set to whatever the user wants even if the keyword argument parameters isn't used such as with pn.Param(MyComponent(name="A name"), name="Another name") that would display Another name as a title
  • set to object.name (how the title is currently determined) if the user doesn't provide name

Note that it would break the following test since the default name would no longer be ParamXXXXX:
https://github.com/holoviz/panel/blob/65fb0fba1287ca8bd9ebbbcfd6b918e30742dea3/panel/tests/test_param.py#L103

Yes, I absolutely think that makes sense.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zassa picture zassa  路  4Comments

maximlt picture maximlt  路  5Comments

lrq3000 picture lrq3000  路  5Comments

MarcSkovMadsen picture MarcSkovMadsen  路  6Comments

kcpevey picture kcpevey  路  4Comments