-
Notifications
You must be signed in to change notification settings - Fork 114
Make data frame selection return row numbers, not pandas index value #677
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f15148e
Make data frame output work correctly with Pandas index
jcheng5 edfec27
Update changelog
jcheng5 dd7b646
Attempt to make test less flaky
jcheng5 028f0ab
render.data_frame: change to iloc instead of loc
jcheng5 8ecb47b
Some output id parameters were documented as input id.
jcheng5 4495366
Update changelog entry to be more accurate
jcheng5 1d8bb33
Sort row selection keys
jcheng5 2b24db3
Don't bother serializing pandas index
jcheng5 64514f3
Merge branch 'main' into row-selection-bug
jcheng5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
This file contains hidden or 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,51 @@ | ||
import pandas as pd | ||
|
||
from shiny import App, Inputs, Outputs, Session, render, ui | ||
|
||
df = pd.DataFrame( | ||
dict( | ||
id=["one", "two", "three"], | ||
fname=["Alice", "Bob", "Charlie"], | ||
lname=["Smith", "Jones", "Brown"], | ||
) | ||
).set_index( # type: ignore | ||
"id", | ||
drop=False, | ||
) | ||
|
||
app_ui = ui.page_fluid( | ||
ui.p("Select rows in the grid, make sure the selected rows appear below."), | ||
ui.output_data_frame("grid"), | ||
ui.output_table("detail"), | ||
ui.output_text_verbatim("debug"), | ||
class_="p-3", | ||
) | ||
|
||
|
||
def server(input: Inputs, output: Outputs, session: Session): | ||
@output | ||
@render.data_frame | ||
def grid(): | ||
return render.DataGrid( | ||
df, | ||
row_selection_mode="multiple", | ||
height=350, | ||
) | ||
|
||
@output | ||
@render.table | ||
def detail(): | ||
if ( | ||
input.grid_selected_rows() is not None | ||
and len(input.grid_selected_rows()) > 0 | ||
): | ||
# "split", "records", "index", "columns", "values", "table" | ||
return df.iloc[list(input.grid_selected_rows())] | ||
|
||
@output | ||
@render.text | ||
def debug(): | ||
return input.grid_selected_rows() | ||
|
||
|
||
app = App(app_ui, server, debug=True) |
29 changes: 29 additions & 0 deletions
29
tests/e2e/bugs/0676-row-selection/test_0676_row_selection.py
This file contains hidden or 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 @@ | ||
from __future__ import annotations | ||
|
||
from conftest import ShinyAppProc | ||
from playwright.sync_api import Page, expect | ||
|
||
|
||
def test_row_selection(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
# The purpose of this test is to make sure that the data grid can work on Pandas | ||
# data frames that use an index that is not simply 0-based integers. | ||
|
||
row1 = page.locator("#grid tbody tr:nth-child(1)") | ||
row3 = page.locator("#grid tbody tr:nth-child(3)") | ||
result_loc = page.locator("#detail tbody tr:nth-child(1) td:nth-child(1)") | ||
debug_loc = page.locator("#debug") | ||
|
||
expect(row3).to_be_visible() | ||
expect(row3.locator("td:nth-child(1)")).to_have_text("three") | ||
expect(debug_loc).to_have_text("()") | ||
|
||
expect(result_loc).not_to_be_attached() | ||
row3.click() | ||
expect(result_loc).to_have_text("three") | ||
expect(debug_loc).to_have_text("(2,)") | ||
|
||
# Ensure that keys are in sorted order, not the order in which they were selected | ||
row1.click() | ||
expect(debug_loc).to_have_text("(0, 2)") |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.