Use key as main identity for st.slider and st.select_slider#12575
Use key as main identity for st.slider and st.select_slider#12575lukasmasuch merged 13 commits intodevelopfrom
key as main identity for st.slider and st.select_slider#12575Conversation
🎉 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) |
✅ PR preview is ready!
|
There was a problem hiding this comment.
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 |
| dyn_val = st.select_slider( | ||
| "Initial dynamic select slider", | ||
| value="orange", | ||
| width="stretch", |
There was a problem hiding this comment.
[question] Why the change in width?
There was a problem hiding this comment.
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.
Describe your changes
If a custom
keyis passed to any of thest.sliderorst.select_sliderwidgets 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
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.