Skip to content

Use key as main identity for st.radio widget#12705

Merged
lukasmasuch merged 3 commits intodevelopfrom
stable-key-identity-radio-widgets
Oct 8, 2025
Merged

Use key as main identity for st.radio widget#12705
lukasmasuch merged 3 commits intodevelopfrom
stable-key-identity-radio-widgets

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Oct 6, 2025

Describe your changes

If a custom key is passed to the st.radio widget it will be used as the main identity. This allows for dynamically changing other parameters in between reruns without causing the widgets to be recreated in the frontend.

GitHub Issue Link (if applicable)

Testing Plan

  • Added unit and e2e tests.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Oct 6, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 6, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12705/streamlit-1.50.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-12705.streamlit.app (☁️ Deploy here if not accessible)

@sfc-gh-lmasuch sfc-gh-lmasuch marked this pull request as ready for review October 6, 2025 20:21
@sfc-gh-lmasuch sfc-gh-lmasuch added security-assessment-completed change:other PR contains other type of change impact:internal PR changes only affect internal code change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users and removed change:other PR contains other type of change impact:internal PR changes only affect internal code labels Oct 6, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch requested a review from Copilot October 6, 2025 20:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements using a custom key as the main identity for st.radio widgets, allowing dynamic parameter changes between reruns without recreating the widget in the frontend. This ensures widget state persistence when non-critical parameters change.

Key changes:

  • Modified radio widget to use key-based identity with whitelisted parameters
  • Added comprehensive unit and E2E tests to verify stable widget IDs and state persistence
  • Updated selectbox implementation to remove format_func from whitelisted identity parameters

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/streamlit/elements/widgets/radio.py Updated radio widget to use key as main identity with options as the only whitelisted parameter
lib/streamlit/elements/widgets/selectbox.py Removed format_func from selectbox whitelisted identity parameters with explanatory comment
lib/tests/streamlit/elements/radio_test.py Added unit tests for stable widget ID behavior and whitelisted parameter validation
e2e_playwright/st_radio.py Added dynamic radio test case with toggle-based parameter switching
e2e_playwright/st_radio_test.py Added E2E test to verify dynamic radio behavior and state persistence

get_radio(themed_app, re.compile(r"^radio 14")), name="st_radio-markdown_label"
)

# Dynamic radio snapshots are tested in dedicated test
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Seems like an unnecessary comment and would be better to remove it.

Copy link
Copy Markdown
Collaborator Author

@lukasmasuch lukasmasuch Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, yep. Cursor added that :) Removed

@lukasmasuch lukasmasuch enabled auto-merge (squash) October 8, 2025 16:45
@lukasmasuch lukasmasuch merged commit 1318f27 into develop Oct 8, 2025
39 checks passed
@lukasmasuch lukasmasuch deleted the stable-key-identity-radio-widgets branch October 8, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants