-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data frame): Restore
input.<ID>_selected_rows()
. Rename `input…
….<ID>_data_view_indices` to `input.<ID>_data_view_rows` (#1377)
- Loading branch information
Showing
12 changed files
with
216 additions
and
56 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
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.
37 changes: 37 additions & 0 deletions
37
tests/playwright/shiny/bugs/1345-render-data-frame-input/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,37 @@ | ||
import pandas as pd | ||
|
||
from shiny import App, Inputs, reactive, render, req, ui | ||
|
||
app_ui = ui.page_fluid( | ||
ui.output_data_frame("df1"), | ||
ui.output_text_verbatim("selected_rows", placeholder=True), | ||
ui.output_text_verbatim("cell_selection", placeholder=True), | ||
) | ||
|
||
|
||
def server(input: Inputs): | ||
df = reactive.Value(pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=["A", "B"])) | ||
|
||
@render.data_frame | ||
def df1(): | ||
return render.DataGrid(df(), selection_mode="rows") | ||
|
||
@render.text | ||
def selected_rows(): | ||
return f"Input selected rows: {input.df1_selected_rows()}" | ||
|
||
@render.text | ||
def cell_selection(): | ||
cell_selection = df1.input_cell_selection() | ||
if cell_selection is None: | ||
req(cell_selection) | ||
raise ValueError("Cell selection is None") | ||
if cell_selection["type"] != "row": | ||
raise ValueError( | ||
f"Cell selection type is not 'row': {cell_selection['type']}" | ||
) | ||
rows = cell_selection["rows"] | ||
return f"Cell selection rows: {rows}" | ||
|
||
|
||
app = App(app_ui, server) |
22 changes: 22 additions & 0 deletions
22
tests/playwright/shiny/bugs/1345-render-data-frame-input/test_1345_input_selected_rows.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,22 @@ | ||
from __future__ import annotations | ||
|
||
from conftest import ShinyAppProc | ||
from controls import OutputDataFrame, OutputTextVerbatim | ||
from playwright.sync_api import Page | ||
|
||
|
||
def test_row_selection(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
df = OutputDataFrame(page, "df1") | ||
selected_rows = OutputTextVerbatim(page, "selected_rows") | ||
cell_selection = OutputTextVerbatim(page, "cell_selection") | ||
|
||
df.expect_n_row(3) | ||
selected_rows.expect_value("Input selected rows: ()") | ||
cell_selection.expect_value("Cell selection rows: ()") | ||
|
||
df.select_rows([0, 2]) | ||
|
||
selected_rows.expect_value("Input selected rows: (0, 2)") | ||
cell_selection.expect_value("Cell selection rows: (0, 2)") |
49 changes: 49 additions & 0 deletions
49
tests/playwright/shiny/bugs/1351-render-data-frame-selected/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,49 @@ | ||
import pandas as pd | ||
|
||
from shiny import App, Inputs, reactive, render, ui | ||
|
||
app_ui = ui.page_fluid( | ||
ui.markdown( | ||
""" | ||
## Description | ||
When you add a row, click on it and click the clear button you get: | ||
""" | ||
), | ||
ui.input_action_button("add_row", "Add row"), | ||
ui.input_action_button("clear_table", "Clear table"), | ||
ui.output_text_verbatim("number_of_selected_rows"), | ||
ui.output_data_frame("df1"), | ||
) | ||
|
||
|
||
def server(input: Inputs): | ||
df = reactive.Value(pd.DataFrame(columns=["A", "B"])) | ||
|
||
@render.data_frame | ||
def df1(): | ||
return render.DataGrid(df(), selection_mode="rows") | ||
|
||
@reactive.effect | ||
@reactive.event(input.add_row) | ||
def _(): | ||
old_df = df() | ||
new_df = pd.concat( # pyright: ignore[reportUnknownMemberType] | ||
[old_df, pd.DataFrame([[1, 2]], columns=["A", "B"])] | ||
) | ||
df.set(new_df) | ||
|
||
@render.text | ||
def number_of_selected_rows(): | ||
df_selected = df1.data_view(selected=True) | ||
return f"Selected rows: {len(df_selected)}" | ||
|
||
@reactive.effect | ||
@reactive.event(input.clear_table) | ||
def _(): | ||
df.set(pd.DataFrame(columns=["A", "B"])) | ||
|
||
|
||
app = App(app_ui, server) |
34 changes: 34 additions & 0 deletions
34
tests/playwright/shiny/bugs/1351-render-data-frame-selected/test_1351_selected_row.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,34 @@ | ||
from __future__ import annotations | ||
|
||
from conftest import ShinyAppProc | ||
from controls import InputActionButton, OutputDataFrame, OutputTextVerbatim | ||
from playwright.sync_api import Page | ||
|
||
|
||
def test_row_selection(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
df = OutputDataFrame(page, "df1") | ||
add_row = InputActionButton(page, "add_row") | ||
clear_table = InputActionButton(page, "clear_table") | ||
selected_rows = OutputTextVerbatim(page, "number_of_selected_rows") | ||
|
||
df.expect_n_row(0) | ||
selected_rows.expect_value("Selected rows: 0") | ||
|
||
add_row.click() | ||
|
||
df.expect_n_row(1) | ||
selected_rows.expect_value("Selected rows: 0") | ||
|
||
df.cell_locator(0, 0).click() | ||
df.select_rows([0]) | ||
|
||
df.expect_n_row(1) | ||
selected_rows.expect_value("Selected rows: 1") | ||
|
||
clear_table.click() | ||
selected_rows.expect_value("Selected rows: 0") | ||
|
||
bad_error_lines = [line for line in local_app.stderr._lines if "INFO:" not in line] | ||
assert len(bad_error_lines) == 0, bad_error_lines |
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
Oops, something went wrong.