Skip to content

Commit 67290e9

Browse files
authored
Revert API changes made in Selected rows method #1121 (#1174)
1 parent d612e1b commit 67290e9

File tree

6 files changed

+28
-31
lines changed

6 files changed

+28
-31
lines changed

examples/dataframe/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ def handle_edit():
9292

9393
@render.text
9494
def detail():
95-
selected_rows = grid.input_selected_rows() or ()
95+
selected_rows = input.grid_selected_rows() or ()
9696
if len(selected_rows) > 0:
9797
# "split", "records", "index", "columns", "values", "table"
98-
return df().iloc[list(grid.input_selected_rows())]
98+
return df().iloc[list(input.grid_selected_rows())]
9999

100100

101101
app = App(app_ui, server)

shiny/api-examples/data_frame/app-core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def summary_data():
4444

4545
@reactive.calc
4646
def filtered_df():
47-
req(summary_data.input_selected_rows())
47+
req(input.summary_data_selected_rows())
4848

49-
# summary_data.selected_rows() is a tuple, so we must convert it to list,
49+
# input.summary_data_selected_rows() is a tuple, so we must convert it to list,
5050
# as that's what Pandas requires for indexing.
51-
selected_idx = list(summary_data.input_selected_rows())
51+
selected_idx = list(input.summary_data_selected_rows())
5252
countries = summary_df.iloc[selected_idx]["country"]
5353
# Filter data for selected countries
5454
return df[df["country"].isin(countries)]

shiny/api-examples/data_frame/app-express.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from shinywidgets import render_widget
44

55
from shiny import reactive, req
6-
from shiny.express import render, ui
6+
from shiny.express import input, render, ui
77

88
# Load the Gapminder dataset
99
df = px.data.gapminder()
@@ -66,12 +66,12 @@ def country_detail_percap():
6666

6767
@reactive.calc
6868
def filtered_df():
69-
req(summary_data.input_selected_rows())
69+
req(input.summary_data_selected_rows())
7070

71-
# summary_data.input_selected_rows() is a tuple, so we must convert it to list,
71+
# input.summary_data_selected_rows() is a tuple, so we must convert it to list,
7272
# as that's what Pandas requires for indexing.
7373

74-
selected_idx = list(summary_data.input_selected_rows())
74+
selected_idx = list(input.summary_data_selected_rows())
7575
countries = summary_df.iloc[selected_idx]["country"]
7676
# Filter data for selected countries
7777
return df[df["country"].isin(countries)]

shiny/render/_dataframe.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,12 @@
22

33
import abc
44
import json
5-
from typing import (
6-
TYPE_CHECKING,
7-
Any,
8-
Literal,
9-
Optional,
10-
Protocol,
11-
Union,
12-
cast,
13-
runtime_checkable,
14-
)
5+
from typing import TYPE_CHECKING, Any, Literal, Protocol, Union, cast, runtime_checkable
156

167
from htmltools import Tag
178

189
from .. import ui
1910
from .._docstring import add_example, no_example
20-
from ..session._utils import require_active_session
2111
from ._dataframe_unsafe import serialize_numpy_dtypes
2212
from .renderer import Jsonifiable, Renderer
2313

@@ -248,7 +238,8 @@ class data_frame(Renderer[DataFrameResult]):
248238
Row selection
249239
-------------
250240
When using the row selection feature, you can access the selected rows by using the
251-
`<data_frame_renderer>.input_selected_rows()` method, where `<data_frame_renderer>` is the render function name that corresponds with the `id=` used in :func:`~shiny.ui.outout_data_frame`. Internally, this method retrieves the selected row value from session's `input.<id>_selected_rows()` value. The value returned will be `None` if no rows
241+
`input.<id>_selected_rows()` function, where `<id>` is the `id` of the
242+
:func:`~shiny.ui.output_data_frame`. The value returned will be `None` if no rows
252243
are selected, or a tuple of integers representing the indices of the selected rows.
253244
To filter a pandas data frame down to the selected rows, use
254245
`df.iloc[list(input.<id>_selected_rows())]`.
@@ -267,6 +258,8 @@ class data_frame(Renderer[DataFrameResult]):
267258
objects you can return from the rendering function to specify options.
268259
"""
269260

261+
# `<data_frame_renderer>.input_selected_rows()` method, where `<data_frame_renderer>` is the render function name that corresponds with the `id=` used in :func:`~shiny.ui.outout_data_frame`. Internally, this method retrieves the selected row value from session's `input.<id>_selected_rows()` value. The value returned will be `None` if no rows
262+
270263
def auto_output_ui(self) -> Tag:
271264
return ui.output_data_frame(id=self.output_id)
272265

@@ -280,14 +273,14 @@ async def transform(self, value: DataFrameResult) -> Jsonifiable:
280273
)
281274
return value.to_payload()
282275

283-
def input_selected_rows(self) -> Optional[tuple[int]]:
284-
"""
285-
When `row_selection_mode` is set to "single" or "multiple" this will return
286-
a tuple of integers representing the rows selected by a user.
287-
"""
276+
# def input_selected_rows(self) -> Optional[tuple[int]]:
277+
# """
278+
# When `row_selection_mode` is set to "single" or "multiple" this will return
279+
# a tuple of integers representing the rows selected by a user.
280+
# """
288281

289-
active_session = require_active_session(None)
290-
return active_session.input[self.output_id + "_selected_rows"]()
282+
# active_session = require_active_session(None)
283+
# return active_session.input[self.output_id + "_selected_rows"]()
291284

292285

293286
@runtime_checkable

tests/playwright/deploys/plotly/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def summary_data():
6161

6262
@reactive.calc
6363
def filtered_df():
64-
req(summary_data.input_selected_rows())
64+
req(input.summary_data_selected_rows())
6565

6666
# input.summary_data_selected_rows() is a tuple, so we must convert it to list,
6767
# as that's what Pandas requires for indexing.
68-
selected_idx = list(summary_data.input_selected_rows())
68+
selected_idx = list(input.summary_data_selected_rows())
6969
countries = summary_df.iloc[selected_idx]["country"]
7070
# Filter data for selected countries
7171
return df[df["country"].isin(countries)]

tests/playwright/shiny/bugs/0676-row-selection/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from __future__ import annotations
2+
3+
from typing import cast
4+
15
import pandas as pd
26

37
from shiny import App, Inputs, Outputs, Session, render, ui
@@ -33,7 +37,7 @@ def grid():
3337

3438
@render.table
3539
def detail():
36-
selected_rows = grid.input_selected_rows() or ()
40+
selected_rows = cast("tuple[int]", input.grid_selected_rows() or ())
3741
if len(selected_rows) > 0:
3842
return df.iloc[list(selected_rows)]
3943

0 commit comments

Comments
 (0)