From 3eeaeaa3220570d8937287b34daa942825577d42 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Tue, 30 Apr 2024 15:57:13 -0500 Subject: [PATCH 1/4] Update data grid/table row selection docs --- .../data-grid/app-variation-select-rows-core.py | 6 +++--- .../app-variation-select-rows-express.py | 4 ++-- components/outputs/data-grid/index.qmd | 15 ++++++++------- .../datatable/app-variation-select-rows-core.py | 4 ++-- .../app-variation-select-rows-express.py | 4 ++-- components/outputs/datatable/index.qmd | 13 +++++++------ 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/components/outputs/data-grid/app-variation-select-rows-core.py b/components/outputs/data-grid/app-variation-select-rows-core.py index ed7fed5b..41cc9584 100644 --- a/components/outputs/data-grid/app-variation-select-rows-core.py +++ b/components/outputs/data-grid/app-variation-select-rows-core.py @@ -13,11 +13,11 @@ def server(input, output, session): @render.data_frame def penguins_df(): - return render.DataGrid(penguins, row_selection_mode="multiple") # << + return render.DataGrid(penguins, selection_mode="rows") # << - @render.ui() + @render.ui def rows(): - rows = input.penguins_df_selected_rows() # << + rows = penguins_df.input_cell_selection()["rows"] # << selected = ", ".join(str(i) for i in sorted(rows)) if rows else "None" return f"Rows selected: {selected}" diff --git a/components/outputs/data-grid/app-variation-select-rows-express.py b/components/outputs/data-grid/app-variation-select-rows-express.py index 5e5c448c..68cf1ade 100644 --- a/components/outputs/data-grid/app-variation-select-rows-express.py +++ b/components/outputs/data-grid/app-variation-select-rows-express.py @@ -9,11 +9,11 @@ @render.ui() def rows(): - rows = input.penguins_df_selected_rows() # << + rows = penguins_df.input_cell_selection()["rows"] # << selected = ", ".join(str(i) for i in sorted(rows)) if rows else "None" return f"Rows selected: {selected}" @render.data_frame def penguins_df(): - return render.DataGrid(penguins, row_selection_mode="multiple") # << + return render.DataGrid(penguins, selection_mode="rows") # << diff --git a/components/outputs/data-grid/index.qmd b/components/outputs/data-grid/index.qmd index c1dac420..7130c523 100644 --- a/components/outputs/data-grid/index.qmd +++ b/components/outputs/data-grid/index.qmd @@ -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._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 + `.input_cell_selection()["rows"]`. apps: - title: Preview file: app-variation-select-rows-core.py @@ -126,13 +127,13 @@ 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._selected_rows()`, where 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 `.input_cell_selection()["rows"]`, where 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._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(.input_cell_selection()["rows"])]`. 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`. diff --git a/components/outputs/datatable/app-variation-select-rows-core.py b/components/outputs/datatable/app-variation-select-rows-core.py index a6ff207f..a9625cb9 100644 --- a/components/outputs/datatable/app-variation-select-rows-core.py +++ b/components/outputs/datatable/app-variation-select-rows-core.py @@ -13,11 +13,11 @@ def server(input, output, session): @render.data_frame def penguins_df(): - return render.DataTable(penguins, row_selection_mode="single") # << + return render.DataTable(penguins, selection_mode="rows") # << @render.ui def rows(): - rows = input.penguins_df_selected_rows() # << + rows = penguins_df.input_cell_selection()["rows"] # << selected = ", ".join(str(i) for i in sorted(rows)) if rows else "None" return f"Rows selected: {selected}" diff --git a/components/outputs/datatable/app-variation-select-rows-express.py b/components/outputs/datatable/app-variation-select-rows-express.py index 7fac1c5b..032e4772 100644 --- a/components/outputs/datatable/app-variation-select-rows-express.py +++ b/components/outputs/datatable/app-variation-select-rows-express.py @@ -9,11 +9,11 @@ @render.ui def rows(): - rows = input.penguins_df_selected_rows() # << + rows = penguins_df.input_cell_selection()["rows"] # << selected = ", ".join(str(i) for i in sorted(rows)) if rows else "None" return f"Rows selected: {selected}" @render.data_frame def penguins_df(): - return render.DataTable(penguins, row_selection_mode="single") # << + return render.DataTable(penguins, selection_mode="rows") # << diff --git a/components/outputs/datatable/index.qmd b/components/outputs/datatable/index.qmd index d0942a84..6e9a8c2d 100644 --- a/components/outputs/datatable/index.qmd +++ b/components/outputs/datatable/index.qmd @@ -45,9 +45,10 @@ listing: dir: components/outputs/datatable/ contents: - title: Select Rows - description: Set `row_selection_mode` in `render.DataTable()` 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._selected_rows()`. + description: Set `selection_mode` in `render.DataTable()` 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 + `.input_cell_selection()["rows"]`. apps: - title: Preview file: app-variation-select-rows-core.py @@ -131,11 +132,11 @@ To make a reactive Data Table, follow three steps: 1. `@output` 2. `@render.data_frame` -A DataTable can also collect input from the user. To allow this, set `render.DataTable(row_selection_mode="single")` or `render.DataTable(row_selection_mode="multiple")` to allow the user to select one or more rows of the DataTable. +A Data Table can also collect input from the user. To allow this, set `render.DataTable(selection_mode="row")` or `render.DataTable(selection_mode="rows")` to allow the user to select one or more rows of the Data Table. -The indices of the selected rows will be accessible within the server function as a reactive variable returned by `input._selected_rows()`, where 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 `.input_cell_selection()["rows"]`, where 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._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(.input_cell_selection()["rows"])]`. 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`. From 24d2bca5a129169c1177d064d28a0b57854e9e7b Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Wed, 1 May 2024 11:19:55 -0500 Subject: [PATCH 2/4] Update instructions --- components/outputs/datatable/index.qmd | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/components/outputs/datatable/index.qmd b/components/outputs/datatable/index.qmd index 6e9a8c2d..90276d92 100644 --- a/components/outputs/datatable/index.qmd +++ b/components/outputs/datatable/index.qmd @@ -127,10 +127,7 @@ To make a reactive Data Table, 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.DataTable()`. Shiny will rerun this function whenever it needs to build or update the output that has the matching id. - 3. Decorate the function with two decorators: - - 1. `@output` - 2. `@render.data_frame` + 3. Decorate the function with `@render.data_frame`. A Data Table can also collect input from the user. To allow this, set `render.DataTable(selection_mode="row")` or `render.DataTable(selection_mode="rows")` to allow the user to select one or more rows of the Data Table. From 81e47bd2d627dfef37ef261542429065d29c552d Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Wed, 1 May 2024 15:55:29 -0500 Subject: [PATCH 3/4] Add links to data frame API docs --- components/outputs/data-grid/index.qmd | 2 ++ components/outputs/datatable/index.qmd | 2 ++ 2 files changed, 4 insertions(+) diff --git a/components/outputs/data-grid/index.qmd b/components/outputs/data-grid/index.qmd index 7130c523..459188bf 100644 --- a/components/outputs/data-grid/index.qmd +++ b/components/outputs/data-grid/index.qmd @@ -135,6 +135,8 @@ The indices of the selected rows will be accessible within the server function a 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(.input_cell_selection()["rows"])]`. +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`. See also: [DataTables](../datatable/index.qmd) diff --git a/components/outputs/datatable/index.qmd b/components/outputs/datatable/index.qmd index 90276d92..842c65ae 100644 --- a/components/outputs/datatable/index.qmd +++ b/components/outputs/datatable/index.qmd @@ -135,6 +135,8 @@ The indices of the selected rows will be accessible within the server function a 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(.input_cell_selection()["rows"])]`. +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`. See also [Data Grids](../data-grid/index.qmd) From e9fa7db9d61eb816016b19a1fb96017c00f1b9be Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Wed, 1 May 2024 15:56:19 -0500 Subject: [PATCH 4/4] Update py-shiny for API docs --- py-shiny | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py-shiny b/py-shiny index c09554d9..b75ba6d7 160000 --- a/py-shiny +++ b/py-shiny @@ -1 +1 @@ -Subproject commit c09554d990c909ad6b1d408c88ad580e22ad9e21 +Subproject commit b75ba6d7b0c2c050892b2abe6309b25800f1e552