panel icon indicating copy to clipboard operation
panel copied to clipboard

Parametrised pn.widget.Select's options are overwritten during widget instantiation.

Open davidandreoletti opened this issue 2 years ago • 0 comments

ALL software version info

Panel: v0.14.0a4 Python: 3.8 Os: macOS 12.4 Browser: safari 15.5

Description of expected behavior and the observed behavior

Problem: The displayed widget has no values filled in.

Expected: The displayed widget has both Prod and Dev values filled in.

Investigation: panel.Param.widget(...) overwrites user provided options (ie ['Prod', 'Dev']) at https://github.com/holoviz/panel/blob/master/panel/param.py#L440

Note: New library user here. The sample code below seems to be a supported use case. If not, please let me know.

Complete, minimal, self-contained example code that reproduces the issue

# Test case 1: No values displayed in the select widget

class HeaderEnvUI(param.Parameterized):
    environment = param.Selector()


header_ui_common = HeaderEnvUI()
header_ui_common_row = pn.Param(
    header_ui_common,
    show_name=False,
    default_layout=pn.Row,
    widgets={
        "environment": {
            "widget_type": pn.widgets.Select,
            "options": ['Prod', 'Dev'],
            "value": 'Prod',
            "size": 1
        }
    }
)

# The UI shows no value in the parametrised displayed Select widget.
# Test Case 2: Values displayed in the select widget


class HeaderEnvUI(param.Parameterized):
    environment = param.Selector(objects= ['Prod', 'Dev'])


header_ui_common = HeaderEnvUI()
header_ui_common_row = pn.Param(
    header_ui_common,
    show_name=False,
    default_layout=pn.Row,
    widgets={
        "environment": {
            "widget_type": pn.widgets.Select,
            "value": 'Prod',
            "size": 1
        }
    }
)

# The UI shows a value in the parametrised displayed Select widget.

Stack traceback and/or browser JavaScript console output

None

Screenshots or screencasts of the bug in action

None

davidandreoletti avatar Jul 28 '22 09:07 davidandreoletti