Skip to content

Use key as main identity for st.slider and st.select_slider#12575

Merged
lukasmasuch merged 13 commits intodevelopfrom
stable-key-identity-slider-widgets
Oct 10, 2025
Merged

Use key as main identity for st.slider and st.select_slider#12575
lukasmasuch merged 13 commits intodevelopfrom
stable-key-identity-slider-widgets

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

Describe your changes

If a custom key is passed to any of the st.slider or st.select_slider widgets 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 Sep 19, 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 Sep 19, 2025

✅ PR preview is ready!

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

@lukasmasuch lukasmasuch requested a review from Copilot September 19, 2025 22:44
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 modifies st.slider and st.select_slider widgets to use the provided key as the main identity when computing element IDs. This allows dynamic property changes without recreating widgets in the frontend, preserving state across reruns.

Key changes:

  • Modified widget identity computation to use keys as main identity with whitelisted parameters
  • Added comprehensive unit tests for stable ID behavior
  • Added E2E tests demonstrating dynamic property updates while preserving widget state

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/streamlit/elements/widgets/slider.py Updated element ID computation to use key as main identity with whitelisted parameters (min_value, max_value, step)
lib/streamlit/elements/widgets/select_slider.py Updated element ID computation to use key as main identity with whitelisted parameters (options, format_func)
lib/tests/streamlit/elements/slider_test.py Added unit tests for stable ID behavior with keys and whitelisted parameter changes
lib/tests/streamlit/elements/select_slider_test.py Added unit tests for stable ID behavior with keys and whitelisted parameter changes
e2e_playwright/st_slider.py Added test app for dynamic slider property updates
e2e_playwright/st_slider_test.py Added E2E test verifying dynamic slider behavior
e2e_playwright/st_select_slider.py Added test app for dynamic select slider property updates
e2e_playwright/st_select_slider_test.py Added E2E test verifying dynamic select slider behavior

@sfc-gh-lmasuch sfc-gh-lmasuch added impact:internal PR changes only affect internal code impact:users PR changes affect end users change:feature PR contains new feature or enhancement implementation security-assessment-completed and removed impact:internal PR changes only affect internal code labels Sep 20, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch marked this pull request as ready for review September 20, 2025 09:22
dyn_val = st.select_slider(
"Initial dynamic select slider",
value="orange",
width="stretch",
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.

[question] Why the change in width?

Copy link
Copy Markdown
Collaborator Author

@lukasmasuch lukasmasuch Oct 9, 2025

Choose a reason for hiding this comment

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

To test that you can dynamically change all (supported) parameters without resetting the component state. This was already working for width, but it doesn't hurt to ensure this in the tests.

Copy link
Copy Markdown
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

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

LGTM

@lukasmasuch lukasmasuch merged commit 7e0a18b into develop Oct 10, 2025
39 checks passed
@lukasmasuch lukasmasuch deleted the stable-key-identity-slider-widgets branch October 10, 2025 18:33
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