Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dataframe row and column selections #8411

Merged
merged 86 commits into from May 13, 2024

Conversation

LukasMasuch
Copy link
Collaborator

@LukasMasuch LukasMasuch commented Apr 2, 2024

Describe your changes

This PR adds row and column selection support to st.dataframe. It can be used like this:

selection = st.dataframe(
    df,
    on_select="rerun",
    selection_mode="single-row"
)
Screen.Recording.2024-04-03.at.19.59.04.mov

GitHub Issue Link (if applicable)

Testing Plan

e2e tests

Edit tasklist title
Beta Give feedback Tasklist e2e tests, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Single row/column selection
    Options
  2. Multi row/column selection
    Options
  3. Mixed selections
    Options
  4. Screenshot of a dataframe with multiple selections
    Options
  5. Clear selections via toolbar
    Options
  6. Clear selections via escape
    Options
  7. Select all rows in multi-row selection via top checkbox
    Options
  8. Optional: Test drag and drop selection
    Options
  9. Optional: Test shift selections
    Options
  10. Optional: Test selections in form
    Options
  11. Have some test cases work with session state and others with return value
    Options
  12. Add a test case validating that the callback gets called
    Options

Contribution License Agreement

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

lib/streamlit/elements/arrow.py Fixed Show fixed Hide fixed
lib/streamlit/elements/arrow.py Fixed Show fixed Hide fixed
lib/streamlit/elements/arrow.py Dismissed Show dismissed Hide dismissed
lib/streamlit/elements/arrow.py Dismissed Show dismissed Hide dismissed
@LukasMasuch LukasMasuch changed the title [WIP] Add dataframe row selections [WIP] Add dataframe row and column selections Apr 17, 2024
@jrieke jrieke mentioned this pull request Apr 19, 2024
2 tasks
@LukasMasuch LukasMasuch marked this pull request as ready for review May 10, 2024 17:30
@LukasMasuch LukasMasuch requested a review from a team as a code owner May 10, 2024 17:30
@LukasMasuch LukasMasuch changed the title [WIP] Add dataframe row and column selections Add dataframe row and column selections May 10, 2024
/**
* On the first rendering, try to load the initial editing state
* from widget state if it exists. This is required in the case
* that other elements are inserted before this widget.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you elaborate a little bit how other elements can impact the editing state of a dataframe widget?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added more to the comment. TLDR: if elements are inserted before, it can happen that the components gets unmounted and loses all state.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

btw. this is the case (problem) for all widgets and even non-widgets e.g. tabs or expander can lose the state as well because of this

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a lot of new / updated logic in this file but no new unit tests are added to DataFrame.test.tsx. Do you think that e2e tests alone are sufficient?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The aspects that got added are quite complicated to test with RTL and it would also mostly do the same as our e2e tests, but in a less complete way. Most of the new logic in Dataframe.tsx is related to widget state handling. I plan to migrate this logic into a dedicated custom hook - e.g. useWidgetState - which would also allow better testing. But its something that will require a dedicated follow-up PR.

Copy link
Collaborator

@raethlein raethlein left a comment

Choose a reason for hiding this comment

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

🚀

@LukasMasuch LukasMasuch merged commit 5c2639b into develop May 13, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants