Use key as main identity for st.dataframe with selections#13558
Merged
lukasmasuch merged 4 commits intodevelopfrom Jan 13, 2026
Merged
Use key as main identity for st.dataframe with selections#13558lukasmasuch merged 4 commits intodevelopfrom
key as main identity for st.dataframe with selections#13558lukasmasuch merged 4 commits intodevelopfrom
Conversation
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Contributor
✅ PR preview is ready!
|
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request implements the key-as-main-identity feature for st.dataframe with selections enabled, allowing widget state to persist when data and other parameters change, as long as the key and whitelisted parameters (selection_mode, is_selection_activated) remain the same.
Changes:
- Modified the identity computation for dataframe widgets with selections to use
keyas the main identity (with whitelisted parameters) - Added comprehensive unit tests to verify ID stability behavior
- Added e2e test to verify selection persistence across data updates
- Improved test locator from
get_by_test_idtoget_by_rolefor better stability
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/streamlit/elements/arrow.py | Changed key_as_main_identity from False to {"selection_mode", "is_selection_activated"} to enable key-based identity for dataframe selections, with helpful comment about edge cases |
| lib/tests/streamlit/elements/arrow_dataframe_test.py | Added DataframeSelectionsStableIdTest class with two test methods: one testing ID stability with key and data changes, another testing that whitelisted parameter changes still cause ID changes |
| e2e_playwright/st_dataframe_selections.py | Added new test section for selection persistence with dynamic data that changes on button click, using session state to track update count |
| e2e_playwright/st_dataframe_selections_test.py | Improved locator to use get_by_role instead of get_by_test_id, and added comprehensive e2e test verifying selections persist after data updates |
sfc-gh-bnisco
approved these changes
Jan 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
If a custom
keyis passed to ast.dataframewith selections activated, it will be used as the main identity. This allows for dynamically changing other parameters and and the input data between reruns without recreating the widgets in the frontend and losing their state.GitHub Issue Link (if applicable)
on_selectis provided #9527Testing 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.