-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug(data frame): Subset selected cells from the filtered rows (#1412)
- Loading branch information
Showing
6 changed files
with
143 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
tests/playwright/shiny/bugs/1390-df-selected-row-filtered/app.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pandas as pd | ||
|
||
from shiny import req | ||
from shiny.express import render, ui | ||
|
||
df = pd.DataFrame(data={"a": [str(i) for i in range(10)]}) | ||
|
||
|
||
with ui.layout_column_wrap(width=1 / 2): | ||
with ui.card(): | ||
ui.card_header("Original data") | ||
|
||
@render.data_frame | ||
def my_df(): | ||
return render.DataGrid(data=df, filters=True, selection_mode="rows") | ||
|
||
with ui.card(): | ||
ui.card_header("Selected data") | ||
|
||
@render.data_frame | ||
def selected_df(): | ||
return my_df.data_view(selected=True) | ||
|
||
with ui.card(): | ||
ui.card_header("Selected rows") | ||
|
||
@render.code | ||
def selected_rows(): | ||
return str(req(my_df.cell_selection() or {}).get("rows", ())) |
87 changes: 87 additions & 0 deletions
87
tests/playwright/shiny/bugs/1390-df-selected-row-filtered/test_1390_selected_row_filtered.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from __future__ import annotations | ||
|
||
import platform | ||
|
||
from conftest import ShinyAppProc | ||
from controls import OutputCode, OutputDataFrame | ||
from playwright.sync_api import Page, expect | ||
|
||
|
||
def test_row_selection(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
my_df = OutputDataFrame(page, "my_df") | ||
selected_df = OutputDataFrame(page, "selected_df") | ||
selected_rows = OutputCode(page, "selected_rows") | ||
|
||
# TODO-karan-test: We should add a locator for selected rows | ||
# TODO-karan-test; We should add a expected selected row count method? | ||
def expect_selected_count(x: OutputDataFrame, n: int) -> None: | ||
expect(x.loc_body.locator("tr[aria-selected=true]")).to_have_count(n) | ||
|
||
my_df.expect_n_row(10) | ||
expect_selected_count(my_df, 0) | ||
selected_df.expect_n_row(0) | ||
selected_rows.expect_value("()") | ||
|
||
# Select row | ||
my_df.select_rows([5, 7]) | ||
my_df.expect_n_row(10) | ||
expect_selected_count(my_df, 2) | ||
selected_df.expect_n_row(2) | ||
selected_rows.expect_value("(5, 7)") | ||
|
||
# # Filter to different row | ||
# Currently this causes an error | ||
my_df.set_column_filter(0, text="5") | ||
my_df.expect_n_row(1) | ||
expect_selected_count(my_df, 1) | ||
selected_df.expect_n_row(1) | ||
selected_rows.expect_value("(5,)") | ||
# # Remove the filter | ||
my_df.set_column_filter(0, text="") | ||
# Confirm the original data frame returns | ||
my_df.expect_n_row(10) | ||
# Confirm the previous row is still selected as no new selection has been made | ||
expect_selected_count(my_df, 2) | ||
selected_df.expect_n_row(2) | ||
selected_rows.expect_value("(5, 7)") | ||
|
||
# Filter to non selected row | ||
# Currently this causes an error | ||
my_df.set_column_filter(0, text="8") | ||
my_df.expect_n_row(1) | ||
expect_selected_count(my_df, 0) | ||
selected_df.expect_n_row(0) | ||
selected_rows.expect_value("()") | ||
|
||
# Remove the filter | ||
# Confirm the original data frame returns | ||
my_df.set_column_filter(0, text="") | ||
my_df.expect_n_row(10) | ||
expect_selected_count(my_df, 2) | ||
selected_df.expect_n_row(2) | ||
selected_rows.expect_value("(5, 7)") | ||
|
||
# Update selection with new selection while under a filter | ||
my_df.set_column_filter(0, text="8") | ||
my_df.expect_n_row(1) | ||
expect_selected_count(my_df, 0) | ||
selected_df.expect_n_row(0) | ||
selected_rows.expect_value("()") | ||
my_df.select_rows([0]) | ||
my_df.set_column_filter(0, text="") | ||
my_df.expect_n_row(10) | ||
expect_selected_count(my_df, 1) | ||
selected_df.expect_n_row(1) | ||
selected_rows.expect_value("(8,)") | ||
|
||
# Remove selection | ||
modifier = "Meta" if platform.system() == "Darwin" else "Control" | ||
for row in (8,): | ||
my_df.cell_locator(row=row, col=0).click( | ||
modifiers=[modifier] | ||
) # TODO-karan-test: Support unselect row method | ||
expect_selected_count(my_df, 0) | ||
selected_df.expect_n_row(0) | ||
selected_rows.expect_value("()") |