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): Add .data_view_rows(), .sort(), .filter(), .update_sort(), and .update_filter(); cell_selection() no longer returns None #1374

Merged
merged 41 commits into from
Jun 3, 2024

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]]
  • .sort: Calc_[ListOrTuple[ColumnSort]]
  • .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 .cell_selection() -> CellSelection | None:

New return type for .cell_selection():

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

def .cell_selection() -> CellSelection:
  • 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 .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.cell_selection() or {}).get("rows", ())

New user interaction:

selected_rows = grid.cell_selection()["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!
shiny/render/_data_frame.py Outdated Show resolved Hide resolved
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)
@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
…lative path (not a subpath like `SUB_FILE`)
* main:
  test(browsers): Unskip webkit tests (#1431)
  chore: update shiny-vscode extension ID (#1434)
  Add setuptools as an install requirement in Python 3.12 and above (#1435)
  Bump version to 0.10.2.9000
  v0.10.2 release candidate
  Use `output_code()` and `render.code()` (#1421)
  Fix: spinners only show for a split second (#1429)
  Bump version to 0.10.1.9000
  Bump version to 0.10.1
  Update CHANGELOG.md (#1419)
  Update cpu info example
  bug(CI): Only update the shiny submodule when making the dev docs (#1417)
  Update shiny CSS (#1415)
  Bump version to 0.10.0.9000 for development
  Bump version to 0.10.0
* main:
  test(conftest): Refactor conftest and controls to be imported as shiny.test module (#1413)
  `make install` shouldn't assume it has `setuptools` (#1437)
@schloerke schloerke changed the title feat(data frame): Expose .data_view_rows(), .input_sort(), .input_filter(), .update_sort(), and .update_filter() feat(data frame): Expose .data_view_rows(), .sort(), .filter(), .update_sort(), and .update_filter() Jun 3, 2024
@schloerke schloerke marked this pull request as ready for review June 3, 2024 15:04
@schloerke schloerke changed the title feat(data frame): Expose .data_view_rows(), .sort(), .filter(), .update_sort(), and .update_filter() feat(data frame): Add .data_view_rows(), .sort(), .filter(), .update_sort(), and .update_filter(); cell_selection() no longer returns None Jun 3, 2024
@schloerke schloerke enabled auto-merge June 3, 2024 15:31
@schloerke schloerke added this pull request to the merge queue Jun 3, 2024
Merged via the queue into main with commit a6a83fe Jun 3, 2024
32 checks passed
@schloerke schloerke deleted the data_view_meta branch June 3, 2024 15:45
schloerke added a commit that referenced this pull request Jun 3, 2024
* main:
  feat(data frame): Add `.data_view_rows()`, `.sort()`, `.filter()`, `.update_sort()`, and `.update_filter()`; `cell_selection()` no longer returns `None` (#1374)
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