Skip to content
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

feat(data frame): Expose .data_view_rows(), .input_sort(), .input_filter(), .update_sort(), and .update_filter() #1374

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

schloerke
Copy link
Collaborator

@schloerke schloerke commented May 13, 2024

Fixes #1351
Fixes #1345
Fixes #1378

Related to #1345 (comment)
Related discussion #1345 (comment) with @pstorozenko

Final solution:

Expose .data_view_info() reactive value which returns DataViewInfo which is defined as a list of data view information.

Expose individual reactive values for the user to access on their own:

  • .data_view_rows: Calc_[tuple[int]]
  • .input_sort: Calc_[ListOrTuple[ColumnSort]]
  • .input_filter: Calc_[ListOrTuple[ColumnFilter]]
  • .update_sort(self, sort: ListOrTuple[ColumnSort | int] | ColumnSort | int | None)
    • int values are upgraded to {col: <INT>, desc: bool}; desc defaults to True if column <INT> is number like, otherwise False.
  • .update_filter(self, sort: ListOrTuple[ColumnFilter] | None)
class ColumnSort(TypedDict):
    col: int
    desc: bool

class ColumnFilterStr(TypedDict):
    col: int
    value: str

class ColumnFilterNumber(TypedDict):
    col: int
    # Similar to...
    value: tuple[float, float] | tuple[float, None] | tuple[None, float]

ColumnFilter = Union[ColumnFilterStr, ColumnFilterNumber]


From #1376

Previous return type for .input_cell_selection():

class CellSelectionNone(TypedDict):
    type: Literal["none"]

class CellSelectionRow(TypedDict):
    type: Literal["row"]
    rows: ListOrTuple[int]

class CellSelectionCol(TypedDict):
    type: Literal["col"]
    cols: ListOrTuple[int]

class CellSelectionRect(TypedDict):
    type: Literal["rect"]
    # Attempt to type the list of size 2, but it is not type enforced
    rows: tuple[int, int] | Annotated[list[int], 2]
    cols: tuple[int, int] | Annotated[list[int], 2]

CellSelection = Union[
    CellSelectionRow,
    CellSelectionCol,
    CellSelectionRect,
    CellSelectionNone,
]

def .input_cell_selection() -> CellSelection | None:

New return type for .input_cell_selection():

class CellSelection(TypedDict):
    type: Literal["none", "row", "col", "rect"]
    rows: ListOrTuple[int]
    cols: ListOrTuple[int]

def .input_cell_selection() -> CellSelection | None:
  • If type = "none", rows and cols are empty tuples.

  • If type = "row", cols is all column numbers of the data.

  • If type = "col", rows is all row numbers of the data view rows

  • If type = "rect", all rows and cols are provided (no longer just min/max values).

  • If .input_cell_selection() receives an empty selection (e.g. type="row" and rows=[], or type="none"), then the return value will be None as no selection is currently taking place.

Previous user interaction:

@render.data_frame
def grid(): ...

selected_rows = (grid.input_cell_selection() or {}).get("rows", ())

New user interaction:

# # Ideal
# selected_rows = grid.input_cell_selection()["rows"]

selected_rows = (grid.input_cell_selection() or { "rows": [] })["rows"]

@schloerke schloerke added this to the v0.9.1 milestone May 13, 2024
* render_df_bugs:
  Update _renderer.py
  Restore `input.<ID>_selected_rows()`. Add tests
  Make sure the index being subsetted is less than the row length, not contained in the index
  Update CHANGELOG.md
  Only subset the selected data if the index row exists!
@@ -275,6 +285,18 @@ def data_view(self, *, selected: bool = False) -> pd.DataFrame:
else:
return self._data_view_all()

data_view_info: reactive.Calc_[DataViewInfo]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add public-facing examples that use this.

For example: an app where there is an interactive table, and below it, a code output that prints out:

  • The values of sort and filter
  • A data frame using rows, which reflects exactly the sorted and filtered data that the user is seeing in the interactive table, and also has an extra column indicating whether that row is selected.
  • Also add a second code output that just prints the value of .data_view(selected=TRUE).

CHANGELOG.md Outdated Show resolved Hide resolved
shiny/render/_data_frame.py Show resolved Hide resolved
shiny/render/_data_frame.py Outdated Show resolved Hide resolved
@schloerke schloerke marked this pull request as draft May 14, 2024 17:55
@schloerke schloerke modified the milestones: v0.9.1, v0.10.0 May 14, 2024
* main:
  test(data frame): Verify that data frame's outputs are reset before moving forward (#1383)
  Send busy/idle at the right times (#1380)
  feat(data frame): Restore `input.<ID>_selected_rows()`. Rename `input.<ID>_data_view_indices` to `input.<ID>_data_view_rows` (#1377)
@jcheng5
Copy link
Collaborator

jcheng5 commented May 17, 2024

After Friday discussion: drop DataViewInfo, instead add rows as another accessor on the renderer. Also, input_cell_selection rows should be ordered the way the user sees it.

* main:
  bug(output transformer): fix transformer auto-registration (#1394)
  fix: Add wait till pulse animation has started (#1393)
  bug(test-deploy): Add retries for deploy tests (#1392)
  Add busy indicator tests (#1391)
  Yield to give "synchronous" writes a chance to complete (#1388)
  chore(busy indicator): Update busy indicator css files (#1389)
  feat(cli): Add `shiny --version` (#1387)
  fix(selectize): Accept jsonifiable values in `options` dictionary (#1382)
  bug(data frame): Use `<ID>_data_view_rows` (#1386)
@schloerke schloerke changed the title feat(data frame): Expose .data_view_info() for @render.data_frame object feat(data frame): Expose .data_view_rows(), .input_column_sort(), .input_column_filter(), .update_column_sort(), and .update_column_filter() May 21, 2024
@schloerke schloerke changed the title feat(data frame): Expose .data_view_rows(), .input_column_sort(), .input_column_filter(), .update_column_sort(), and .update_column_filter() feat(data frame): Expose .data_view_rows(), .input_sort(), .input_filter(), .update_sort(), and .update_filter() May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data frame Related to @render.data_frame
Projects
None yet
3 participants