-
Notifications
You must be signed in to change notification settings - Fork 21
Update data grid/table row selection docs #143
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,9 +45,10 @@ listing: | |
| dir: components/outputs/data-grid/ | ||
| contents: | ||
| - title: Select Rows | ||
| description: Set `row_selection_mode` in `render.DataGrid()` to `"single"` to | ||
| allow the user to select one row at a time. Set it to `"multiple"` to allow | ||
| the user to select multiple rows at a time. Access the selection(s) as `input.<id>_selected_rows()`. | ||
| description: Set `selection_mode` in `render.DataGrid()` to `"row"` to | ||
| allow the user to select one row at a time. Set it to `"rows"` to allow | ||
| the user to select multiple rows at a time. Access the selection(s) as | ||
| `<id>.input_cell_selection()["rows"]`. | ||
| apps: | ||
| - title: Preview | ||
| file: app-variation-select-rows-core.py | ||
|
|
@@ -126,13 +127,15 @@ To make a reactive Data Grid, follow three steps: | |
|
|
||
| 2. Within the server function, define a new function whose name matches the id used above. The function should assemble the table to display and then return the table wrapped in `render.DataGrid()`. Shiny will rerun this function whenever it needs to build or update the output that has the matching id. | ||
|
|
||
| 3. Decorate the function with `@render.data_frame` | ||
| 3. Decorate the function with `@render.data_frame`. | ||
|
|
||
| A Data Grid can also collect input from the user. To allow this, set `render.DataGrid(row_selection_mode="single")` or `render.DataGrid(row_selection_mode="multiple")` to allow the user to select one or more rows of the Data Grid. | ||
| A Data Grid can also collect input from the user. To allow this, set `render.DataGrid(selection_mode="row")` or `render.DataGrid(selection_mode="rows")` to allow the user to select one or more rows of the Data Grid. | ||
|
|
||
| The indices of the selected rows will be accessible within the server function as a reactive variable returned by `input.<id>_selected_rows()`, where <id> is the id of the `ui.output_data_frame()` associated with the table. | ||
| The indices of the selected rows will be accessible within the server function as a reactive variable returned by `<name>.input_cell_selection()["rows"]`, where <name> is the name of the function decorated with `@render.data_frame`. | ||
|
|
||
| The value returned will be `None` if no rows are selected, or a tuple of integers representing the indices of the selected rows. To filter a pandas data frame down to the selected rows, use `df.iloc[list(input.<id>_selected_rows())]`. | ||
| The value returned will be an empty tuple if no rows are selected, or a tuple of integers representing the indices of the selected rows. To filter a pandas data frame down to the selected rows, use `df.iloc[list(<name>.input_cell_selection()["rows"])]`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the very least, I think this section should give the user a hint that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea -- I've added a bit of info and link to the API docs. |
||
|
|
||
| For more information about interacting with data frames, see the API documentation for [Express](../../../api/express/express.render.data_frame.qmd) or [Core](../../../api/core/render.data_frame.qmd) syntax. | ||
|
|
||
| If your table is a data frame that uses the pandas styler, replace `ui.output_data_frame()` with `ui.output_table()` and `@render.data_frame` with `@render.table`. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good change in the sense of having the existing example run correctly with shiny 0.9.0.
We don't necessarily need to do it in this PR, but this example is less motivating now that the output object has more methods. It'd be nice if this example or a variant in this section gave more instruction about those methods and how to use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that there should be an example that shows other methods. I think it makes sense to merge now and then when @schloerke, discuss with him about other examples.