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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
21db322
Add initial version of row selection
lukasmasuch Apr 2, 2024
c9eadfe
Update selection state format
lukasmasuch Apr 2, 2024
d1a530a
Merge remote-tracking branch 'remote/develop' into feature/dataframe-…
lukasmasuch Apr 2, 2024
40f4587
Fix signature
lukasmasuch Apr 3, 2024
5648987
Improve frontend handling
lukasmasuch Apr 3, 2024
1e9b6eb
Update to alpha 7
lukasmasuch Apr 3, 2024
efd109b
Fix debounce
lukasmasuch Apr 3, 2024
4908f44
Additional flag
lukasmasuch Apr 3, 2024
0598148
Prevent circular import
lukasmasuch Apr 3, 2024
8738d80
Fix test
lukasmasuch Apr 3, 2024
9416a71
Minor improvement
lukasmasuch Apr 3, 2024
2543295
Add dataframe selection demo
lukasmasuch Apr 3, 2024
9e4b885
Update docs and parameters
lukasmasuch Apr 3, 2024
a1ee458
Merge remote-tracking branch 'remote/develop' into feature/dataframe-…
lukasmasuch Apr 11, 2024
2ce63db
Merge remote-tracking branch 'remote/develop' into feature/dataframe-…
lukasmasuch Apr 15, 2024
251f506
Merge remote-tracking branch 'remote/develop' into feature/dataframe-…
lukasmasuch Apr 16, 2024
04f93d6
Add colum selection mode
lukasmasuch Apr 17, 2024
bcd1243
Fix issue
lukasmasuch Apr 17, 2024
603b6ee
Keep old selections
lukasmasuch Apr 17, 2024
08a1dea
Always use the square checkbox
lukasmasuch Apr 17, 2024
3ea3c74
Merge remote-tracking branch 'remote/develop' into feature/dataframe-…
lukasmasuch Apr 19, 2024
902fbe1
Merge remote-tracking branch 'upstream/develop' into feature/datafram…
lukasmasuch Apr 19, 2024
06ee053
Add cache replay check
lukasmasuch Apr 19, 2024
a391e69
Minor dataframe related improvements
lukasmasuch Apr 20, 2024
2df122c
Merge remote-tracking branch 'upstream/develop' into feature/datafram…
lukasmasuch Apr 30, 2024
46286b0
Sorted list
lukasmasuch Apr 30, 2024
16d7a4e
Apply some refactorings
lukasmasuch Apr 30, 2024
c9bbfa5
Add some tests
lukasmasuch Apr 30, 2024
386bd9a
Remove unused import
lukasmasuch Apr 30, 2024
80c1aba
Some more minor improvements
lukasmasuch Apr 30, 2024
017703e
Fix test
lukasmasuch Apr 30, 2024
217e60b
Merge remote-tracking branch 'upstream/develop' into feature/datafram…
lukasmasuch May 7, 2024
d0d2b19
Fix comment in proto
lukasmasuch May 7, 2024
81d097c
Add more tests
lukasmasuch May 7, 2024
11e8955
Fix comment
lukasmasuch May 7, 2024
cc7b8c7
Move import
lukasmasuch May 7, 2024
149f5a9
Add comment
lukasmasuch May 7, 2024
4b9ee04
Change comment
lukasmasuch May 7, 2024
29410a0
Some more cleanup
lukasmasuch May 7, 2024
b0664b8
Fix wrong check
lukasmasuch May 7, 2024
b883043
Fix test
lukasmasuch May 7, 2024
f803275
Move selection logic into dedicated hook
lukasmasuch May 8, 2024
215e5f4
Fix comment
lukasmasuch May 8, 2024
3c33fd7
Some refactoring
lukasmasuch May 8, 2024
2de0e95
Add comment
lukasmasuch May 8, 2024
fa0372f
Merge remote-tracking branch 'upstream/develop' into feature/datafram…
lukasmasuch May 8, 2024
8536471
Apply some fixes
lukasmasuch May 8, 2024
2464176
Update test
lukasmasuch May 8, 2024
389a079
Merge branch 'develop' into feature/dataframe-selections
lukasmasuch May 8, 2024
b7351b3
Add custom hook unit tests
lukasmasuch May 8, 2024
6a8c080
Merge branch 'feature/dataframe-selections' of https://github.com/str…
lukasmasuch May 8, 2024
a1d2ddd
Fix imports
lukasmasuch May 8, 2024
ba29b8d
Add more unit tests
lukasmasuch May 8, 2024
8650241
Add e2e tests for the dataframe selections (#8634)
raethlein May 10, 2024
3857185
Address e2e tests feedback
raethlein May 10, 2024
a47fb97
Update variable name
raethlein May 10, 2024
accd2c7
Merge remote-tracking branch 'upstream/develop' into feature/datafram…
lukasmasuch May 10, 2024
735edce
Merge branch 'feature/dataframe-selections' of https://github.com/str…
lukasmasuch May 10, 2024
90017ba
Add comment
lukasmasuch May 10, 2024
0875b51
Use glide type
lukasmasuch May 10, 2024
ea3db97
Rename
lukasmasuch May 10, 2024
9991cf6
Update comment
lukasmasuch May 10, 2024
ad637a2
Update comment
lukasmasuch May 10, 2024
fd53dd4
Added comment
lukasmasuch May 10, 2024
d5fb1d0
Removed not required dependencies
lukasmasuch May 10, 2024
1a9c9e7
Add comment
lukasmasuch May 10, 2024
494cd67
Fix clear on submit for form
lukasmasuch May 10, 2024
27157e9
Remove unused import
lukasmasuch May 10, 2024
3258e79
Merge remote-tracking branch 'upstream/develop' into feature/datafram…
lukasmasuch May 10, 2024
78bd3ce
Remove clearCellSelections callback
lukasmasuch May 10, 2024
8040a74
Add comment
lukasmasuch May 10, 2024
535ab67
Move the disabled checks up
lukasmasuch May 10, 2024
3e999e2
Update glide data grid to alpha 8
lukasmasuch May 10, 2024
2f9886d
Add reconstruction of selection state
lukasmasuch May 10, 2024
06e01c5
Merge remote-tracking branch 'upstream/develop' into feature/datafram…
lukasmasuch May 10, 2024
0e86a12
Additional improvements
lukasmasuch May 10, 2024
b2f6d70
Update snapshots
lukasmasuch May 10, 2024
25e54d2
Update snapshot
lukasmasuch May 10, 2024
2bb8f26
Skip firefox
lukasmasuch May 10, 2024
f74401c
Add comment
lukasmasuch May 10, 2024
68cf17b
Improve e2e-test text-expectation check
raethlein May 13, 2024
bce225a
Add test for usage in fragment
lukasmasuch May 13, 2024
cf2e3b1
Fix issue with selections on cell selection
lukasmasuch May 13, 2024
37a6e34
Remove console log
lukasmasuch May 13, 2024
e4f2c54
Fix e2e test
lukasmasuch May 13, 2024
ee68976
Clean up tests
lukasmasuch May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions e2e_playwright/st_dataframe_selections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import random
import time

import numpy as np
import pandas as pd

import streamlit as st

np.random.seed(0)
random.seed(0)

# Generate a random dataframe
df = pd.DataFrame(
np.random.randn(5, 5),
columns=("col_%d" % i for i in range(5)),
)

# set fixed column with so our pixel-clicks in the test are stable
column_with_fixed_width = st.column_config.Column(width="small")
column_config = {
"col_0": column_with_fixed_width,
"col_1": column_with_fixed_width,
"col_2": column_with_fixed_width,
"col_3": column_with_fixed_width,
"col_4": column_with_fixed_width,
}

st.header("Row & column selections:")
st.subheader("single-row select")
selection = st.dataframe(
df,
hide_index=True,
on_select="rerun",
selection_mode="single-row",
column_config=column_config,
)
st.write("Dataframe single-row selection:", str(selection))

st.subheader("single-column select")
selection = st.dataframe(
df,
hide_index=True,
on_select="rerun",
selection_mode="single-column",
column_config=column_config,
)
st.write("Dataframe single-column selection:", str(selection))

st.subheader("multi-row select")
selection = st.dataframe(
df,
hide_index=True,
on_select="rerun",
selection_mode="multi-row",
column_config=column_config,
)
st.write("Dataframe multi-row selection:", str(selection))

st.subheader("multi-column select")
selection = st.dataframe(
df,
hide_index=True,
on_select="rerun",
selection_mode="multi-column",
column_config=column_config,
)
st.write("Dataframe multi-column selection:", str(selection))

if st.button("Create some elements to unmount component"):
for _ in range(3):
# The sleep here is needed, because it won't unmount the
# component if this is too fast.
time.sleep(1)
st.write("Another element")

st.subheader("multi-row & multi-column select")
selection = st.dataframe(
df,
hide_index=True,
on_select="rerun",
selection_mode=["multi-row", "multi-column"],
column_config=column_config,
)
st.write("Dataframe multi-row-multi-column selection:", str(selection))

st.header("Selections in form:")

with st.form(key="my_form", clear_on_submit=True):
selection = st.dataframe(
df,
hide_index=True,
on_select="rerun",
selection_mode=["multi-row", "multi-column"],
key="df_selection_in_form",
column_config=column_config,
)
st.form_submit_button("Submit")

st.write("Dataframe-in-form selection:", str(selection))
if "df_selection_in_form" in st.session_state:
st.write(
"Dataframe-in-form selection in session state:",
str(st.session_state.df_selection_in_form),
)

st.header("Selection callback:")


def on_selection():
st.write("Dataframe selection callback:", str(st.session_state.df_selection))


st.dataframe(
df,
hide_index=True,
on_select=on_selection,
selection_mode=["multi-row", "multi-column"],
key="df_selection",
column_config=column_config,
)

st.header("Selections in fragment:")


@st.experimental_fragment()
def test_fragment():
selection = st.dataframe(
df,
hide_index=True,
on_select="rerun",
selection_mode=["multi-row", "multi-column"],
key="inside_fragment",
column_config=column_config,
)
st.write("Dataframe-in-fragment selection:", str(selection))


test_fragment()

if "runs" not in st.session_state:
st.session_state.runs = 0
st.session_state.runs += 1
st.write("Runs:", st.session_state.runs)
Loading
Loading