Skip to content

Commit

Permalink
Add height parameter and scrolling to gr.Dataframe (#5283)
Browse files Browse the repository at this point in the history
* add height and scrolling to dataframe

* add changeset

* fix test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
abidlabs and gradio-pr-bot committed Aug 22, 2023
1 parent 804fcc0 commit a746055
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/wide-worlds-yawn.md
@@ -0,0 +1,6 @@
---
"@gradio/dataframe": minor
"gradio": minor
---

feat:Add height parameter and scrolling to `gr.Dataframe`
6 changes: 6 additions & 0 deletions gradio/components/dataframe.py
Expand Up @@ -54,6 +54,7 @@ def __init__(
label: str | None = None,
every: float | None = None,
show_label: bool | None = None,
height: int | float | None = None,
scale: int | None = None,
min_width: int = 160,
interactive: bool | None = None,
Expand All @@ -79,6 +80,7 @@ def __init__(
label: component name in interface.
every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
show_label: if True, will display label.
height: The maximum height of the file component, in pixels. If more files are uploaded than can fit in the height, a scrollbar will appear.
scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
interactive: if True, will allow users to edit the dataframe; if False, can only be used to display data. If not provided, this is inferred based on whether the component is used as an input or output.
Expand Down Expand Up @@ -129,6 +131,7 @@ def __init__(
if latex_delimiters is None:
latex_delimiters = [{"left": "$", "right": "$", "display": False}]
self.latex_delimiters = latex_delimiters
self.height = height

self.select: EventListenerMethod
"""
Expand Down Expand Up @@ -163,6 +166,7 @@ def get_config(self):
"overflow_row_behaviour": self.overflow_row_behaviour,
"wrap": self.wrap,
"latex_delimiters": self.latex_delimiters,
"height": self.height,
**IOComponent.get_config(self),
}

Expand All @@ -176,6 +180,7 @@ def update(
latex_delimiters: list[dict[str, str | bool]] | None = None,
scale: int | None = None,
min_width: int | None = None,
height: int | float | None = None,
interactive: bool | None = None,
visible: bool | None = None,
):
Expand All @@ -186,6 +191,7 @@ def update(
"show_label": show_label,
"scale": scale,
"min_width": min_width,
"height": height,
"interactive": interactive,
"visible": visible,
"value": value,
Expand Down
2 changes: 2 additions & 0 deletions js/dataframe/interactive/InteractiveDataframe.svelte
Expand Up @@ -22,6 +22,7 @@
right: string;
display: boolean;
}[];
export let height: number | undefined = undefined;
let old_value: string = JSON.stringify(value);
export let value_is_output = false;
Expand Down Expand Up @@ -79,5 +80,6 @@
{wrap}
{datatype}
{latex_delimiters}
{height}
/>
</Block>
7 changes: 4 additions & 3 deletions js/dataframe/shared/Table.svelte
Expand Up @@ -27,6 +27,7 @@
export let editable = true;
export let wrap = false;
export let height: number | undefined = undefined;
let selected: false | string = false;
Expand Down Expand Up @@ -539,7 +540,7 @@
{label}
</p>
{/if}
<div class="table-wrap scroll-hide" class:dragging class:no-wrap={!wrap}>
<div class="table-wrap" class:dragging class:no-wrap={!wrap} style="max-height: {typeof height === undefined ? 'auto' : height + 'px'};">
<Upload
flex={false}
center={false}
Expand Down Expand Up @@ -703,8 +704,8 @@
transition: 150ms;
border: 1px solid var(--border-color-primary);
border-radius: var(--table-radius);
overflow-x: scroll;
overflow-y: hidden;
overflow-x: auto;
overflow-y: auto;
}
.dragging {
Expand Down
2 changes: 2 additions & 0 deletions js/dataframe/static/StaticDataframe.svelte
Expand Up @@ -31,6 +31,7 @@
right: string;
display: boolean;
}[];
export let height: number | undefined = undefined;
const dispatch = createEventDispatcher();
Expand Down Expand Up @@ -78,5 +79,6 @@
{datatype}
{latex_delimiters}
editable={false}
{height}
/>
</Block>
2 changes: 2 additions & 0 deletions test/test_components.py
Expand Up @@ -1140,6 +1140,7 @@ def test_component_functions(self):
"interactive": None,
"root_url": None,
"wrap": False,
"height": None,
"latex_delimiters": [{"display": False, "left": "$", "right": "$"}],
}
dataframe_input = gr.Dataframe()
Expand Down Expand Up @@ -1175,6 +1176,7 @@ def test_component_functions(self):
"interactive": None,
"root_url": None,
"wrap": False,
"height": None,
"latex_delimiters": [{"display": False, "left": "$", "right": "$"}],
}

Expand Down

0 comments on commit a746055

Please sign in to comment.