holoviz/panel

Feature Request: Access label of "select-like" elements through property

Open

#6,274 opened on Jan 26, 2024

View on GitHub
 (5 comments) (1 reaction) (0 assignees)Python (615 forks)auto 404
good first issuetype: enhancement

Repository metrics

Stars
 (5,722 stars)
PR merge metrics
 (PR metrics pending)

Description

When creating a select-like element with different values and labels, we can only access the value directly, but not the label.

Current way

import panel as pn
pn.extension()
radio = pn.widgets.RadioBoxGroup(
    name="MultiSelect Example",
    options={"one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6},
    value=3,
)
radio

image

radio.value

image

Current workaround

def get_selected_label(radio_group):
    return list(radio_group.options.keys())[list(radio_group.options.values()).index(radio_group.value)]

selected_label = get_selected_label(radio)
print(selected_label)

image

Proposed solution

What I want is to access the selected label through a property.

Have a property such as

radio.label

image

That acts the same as the get_selected_label function above.

Contributor guide