Fixing state management issues with Streamlit's st.pills component where selections get reset when available options change dynamically and pills require double-clicks to toggle

I’m experiencing state management issues with st.pills when the available options change dynamically based on other user selections. The main problems are:

  1. Double-click requirement: When something is already selected, I need to click twice on pills to toggle them

  2. State reset: When I add new selections in a parent category that changes available options in child categories, previously selected items in child categories get reset/cleared

Use Case

I have a hierarchical selection UI:

  • Device Types (st.pills) → determines available Model Groups

  • Model Groups (st.pills) → determines available Model Numbers

  • Model Numbers (st.pills)

When a user selects additional device types, new model groups become available, but previously selected model groups/numbers get cleared.

Expected Behavior

  • Single click should toggle pill selection

  • When parent selections change and new options become available, previously selected items that are still valid should remain selected

  • Only invalid selections (no longer available) should be cleared