Skip to content

Use key as main identity for st.dataframe with selections#13558

Merged
lukasmasuch merged 4 commits intodevelopfrom
feature/key-as-main-identity-for-dataframe-selections
Jan 13, 2026
Merged

Use key as main identity for st.dataframe with selections#13558
lukasmasuch merged 4 commits intodevelopfrom
feature/key-as-main-identity-for-dataframe-selections

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Jan 11, 2026

Describe your changes

If a custom key is passed to a st.dataframe with 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)

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 Jan 11, 2026

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

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 11, 2026

✅ PR preview is ready!

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

@lukasmasuch lukasmasuch added security-assessment-completed change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Jan 11, 2026
@sfc-gh-lmasuch sfc-gh-lmasuch marked this pull request as ready for review January 11, 2026 20:13
Copilot AI review requested due to automatic review settings January 11, 2026 20:13
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 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 key as 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_id to get_by_role for 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

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!

@lukasmasuch lukasmasuch merged commit ee6224a into develop Jan 13, 2026
44 of 45 checks passed
@lukasmasuch lukasmasuch deleted the feature/key-as-main-identity-for-dataframe-selections branch January 13, 2026 10:59
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.

Flickering Dataframe when using st.fragment, but only when on_select is provided

3 participants