panel
panel copied to clipboard
Regression: Names of Parameterized options not used as labels of Selectors
Panel 0.13.1
import panel as pn
component1=pn.panel("Value1")
component2=pn.panel("Value2")
selection = pn.widgets.RadioBoxGroup(value=component1, options=[component1, component2])
pn.Column(
selection
).servable()
shows
I would expect "Value1" and "Value2" to be shown as labels. It used to be like that and it was simple and powerful.
Even if it worked before, I'm not sure it should actually have, as I find this usage as shown in the example pretty confusing. Do you have a more specific use case in mind that would motivate supporting that?
I can't think of any mechanism that would have allowed this to work in the past tbh. I'm -0 on supporting this, I think it's not unreasonable to support but it seems of very limited utility. The .object
of a pane is very rarely something that would make sense as an option label (e.g. what happens for non-string types and what happens if the string is very long). It does seem better to be explicit about the actual label.
Also just tested all Panel versions in the 0.11.x, 0.12.x series as well as 0.13.0 and this has never worked as far as I can tell. Therefore I'm going to close as invalid.
The reason why I also think this is wrong is that the .object
of a pane is mutable. If you update it and the label does not also update it is very confusing.
Was this maybe the intent of the original post?
import panel as pn
pn.extension()
component1=pn.panel("Value1", name="V1")
component2=pn.panel("Value2", name="V2")
selection = pn.widgets.RadioBoxGroup(value=component1, options=[component1, component2])
pn.Column(
selection
).servable()
In that case I would have expected name
to be used as the option label, but it isn't:
I don't know if using name=
is something we want to promote. name=
is used as the label for many widgets and there's been discussion (e.g. https://github.com/holoviz/panel/issues/2834) to migrate to title=
.
Sure, but it's worth checking if it used to work this way...
I've checked panel==0.10.0/ param==1.9.3 with this example
import param
import panel as pn
class MyClass(param.Parameterized):
value = param.Number()
options = [
MyClass(name="obj1"), MyClass(name="obj2")
]
pn.widgets.Select(options=options).servable()
It does not work.
I simply don't understand it. In my head I've used that so many times :-)
I would still argue it is very valuable to support and very much in line with how the Parameter Subobjects example works for parameterized classes and how Tabs
works. I would very much appreciate you reconsider @philippjfr. It would make using widgets to select between parameterized objects/ subcomponents much easier that having to construct a dictionary and hand that around together with the objects.
Parameter Subobjects
import param
import panel as pn
options = [pn.panel("Value1", name="value1"), pn.panel("Value2", name="value2")]
class MyOptionsClass(param.Parameterized):
value = param.Selector(objects=options)
my_options = MyOptionsClass()
pn.Param(my_options, widgets={"value": pn.widgets.RadioBoxGroup}, expand_button=False).servable()
Tabs
import panel as pn
options = [pn.panel("Value1", name="value1"), pn.panel("Value2", name="value2")]
pn.Tabs(*options).servable()
Wait, that example is very different from the example you had posted originally. I fully agree that the name
parameter should be used.
I'm using the other examples because I believe they are all should behave similar using the name
parameter.
I guess I thought the widgets would use the name
parameter by default because I've been using the param.Selector
and pn.Param
so much. I thought it was the widget that used the name
parameter by default. But it seems Param
does the magic.
Ahh. I forgot the
Was this maybe the intent of the original post?
import panel as pn pn.extension() component1=pn.panel("Value1", name="V1") component2=pn.panel("Value2", name="V2") selection = pn.widgets.RadioBoxGroup(value=component1, options=[component1, component2]) pn.Column( selection ).servable()
In that case I would have expected
name
to be used as the option label, but it isn't:
Yes. This was the initial example I would like to display the value of the name
parameter. But it looks like
Ah, ok. You confused us all with an apparently actual issue with an accurate issue title but the wrong code snippet. :-) I too think it used to say V1
where it now says Markdown(str, name='V1')
, and V1
seems much more appropriate.