How can I edit a panel button so the labels displayed are different from the attribute values?
Here is an example:
import panel as pn
import panel.widgets as pnw
variable_type = ('ptmp', 'sal')
variable_name=('Temperature',
'Salinity')
variables = pnw.Select(name='Variable', value='ptmp',
options=list(variable_type),
)
variables.show()
Because my button is linked to other panel objects, I cannot change the value and options of the widget. I was wondering if there is an easy way to add an extra variable that would edit the “label” displayed.
I tried modifying the labels
argument with :
variables = pnw.Select(name='Variable', value='ptmp',
options=list(variable_type),
labels=list(variable_name),
)
But I don’t think it is the way to do it… I got this error:
WARNING:param.Variable: Setting non-parameter attribute labels=['Temperature', 'Salinity'] using a mechanism intended only for parameters
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-10-7d643d032a20> in <module>
6 'Salinity')
7
----> 8 variables = pnw.Select(name='Variable', value='ptmp',
9 options=list(variable_type),
10 labels=list(variable_name),
[...]
~/opt/anaconda3/envs/analysis_eel_data/lib/python3.9/site-packages/param/parameterized.py in _setup_params(self_, **params)
1290 self.param.warning("Setting non-parameter attribute %s=%s using a mechanism intended only for parameters", name, val)
1291 # i.e. if not desc it's setting an attribute in __dict__, not a Parameter
-> 1292 setattr(self, name, val)
1293
1294 @classmethod
AttributeError: can't set attribute
Is there an easy way to do that?