Skip to content

Commit

Permalink
Allow accessing the entire row of selected values in gr.DataFrame (#…
Browse files Browse the repository at this point in the history
…9128)

* s

* changes

* docstring

* add changeset

* format

* typing

* revert

* add changeset

* changes

* add changeset

* add changeset

* js

* add changeset

* remove col value

* lint

---------

Co-authored-by: gradio-pr-bot <[email protected]>
  • Loading branch information
abidlabs and gradio-pr-bot authored Aug 20, 2024
1 parent f1ef94a commit 747013b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/easy-geese-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@gradio/dataframe": minor
"@gradio/utils": minor
"gradio": minor
---

feat:Allow accessing the entire row of selected values in `gr.DataFrame`
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ gradio/launches.json
flagged/
gradio_cached_examples/
tmp.zip
gradio/hash_seed.txt

# Tests
.coverage
Expand Down
8 changes: 8 additions & 0 deletions gradio/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ def __init__(self, target: Block | None, data: Any):
"""
The value of the selected item.
"""
self.row_value: Any = data.get("row_value")
"""
The value of the entire row that the selected item belongs to, as a 1-D list. Only implemented for the `Dataframe` component, returns None for other components.
"""
self.col_value: Any = data.get("col_value")
"""
The value of the entire row that the selected item belongs to, as a 1-D list. Only implemented for the `Dataframe` component, returns None for other components.
"""
self.selected: bool = data.get("selected", True)
"""
True if the item was selected, False if deselected.
Expand Down
6 changes: 5 additions & 1 deletion js/dataframe/shared/Table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
if (selected !== false) {
const [row, col] = selected;
if (!isNaN(row) && !isNaN(col)) {
dispatch("select", { index: [row, col], value: get_data_at(row, col) });
dispatch("select", {
index: [row, col],
value: get_data_at(row, col),
row_value: data[row].map((d) => d.value)
});
}
}
}
Expand Down
1 change: 1 addition & 0 deletions js/utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ActionReturn } from "svelte/action";
import type { Client } from "@gradio/client";

export interface SelectData {
row_value?: any[];
index: number | [number, number];
value: any;
selected?: boolean;
Expand Down

0 comments on commit 747013b

Please sign in to comment.