streamlit / streamlit

Streamlit — A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
35.7k stars 3.09k forks source link

segmented_control with a required value #9870

Open RubenVanEldik opened 10 hours ago

RubenVanEldik commented 10 hours ago

Checklist

Summary

Hi all,

The segmented_control component is a fantastic new component that I think will be used a lot by Streamlit users.

However, I currently miss 1 option, that is to require a value. For example, now it is possible to provide a default value which can be unclicked.

Why?

In many use cases where segmented_control will be used in a single mode, the developer might want to force the user to select something.

How?

I propose to expand the segmented_control (and pills) API by adding an extra parameter 'required' . If required is True, a value must always be selected.

options = ["North", "East", "South", "West"]
selection = st.segmented_control(
    "Directions",
    options,
    selection_mode="single",
    required=True,
    default="South",
)
github-actions[bot] commented 10 hours ago

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits

jrieke commented 16 minutes ago

Somewhat related: #7165