Skip to content

Conversation

hannahblair
Copy link
Collaborator

Description

Adds a truncate_headers param to allow for better control over how the headers behave. Set to default to True for backwards compatibility.

Closes: #11929

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Testing and Formatting Your Code

  1. PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up your Gradio environment locally and run the backed tests: bash scripts/run_backend_tests.sh

  2. Please run these bash scripts to automatically format your code: bash scripts/format_backend.sh, and (if you made any changes to non-Python files) bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Sep 18, 2025

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website building...
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/58e7726f1882516b6f18cccfa06889cc3455d48d/gradio-5.48.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@58e7726f1882516b6f18cccfa06889cc3455d48d#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/58e7726f1882516b6f18cccfa06889cc3455d48d/gradio-client-1.19.1.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Sep 18, 2025

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/dataframe patch
gradio patch

  • Add truncate_headers parameter to Dataframe to improve header text control

‼️ Changeset not approved. Ensure the version bump is appropriate for all packages before approving.

  • Maintainers can approve the changeset by checking this checkbox.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@hannahblair hannahblair marked this pull request as ready for review September 23, 2025 14:01
@abidlabs abidlabs self-requested a review September 23, 2025 14:29
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

Looks good to me @hannahblair ! What if this parameter can also take a list of column names to give developers even more control as opposed to all headers are truncated or none are?

show_search: Literal["none", "search", "filter"] = "none",
pinned_columns: int | None = None,
static_columns: list[int] | None = None,
truncate_headers: bool = True,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's also add to docstring

@abidlabs
Copy link
Member

abidlabs commented Sep 23, 2025

Thanks @hannahblair! This helps for sure, see previous (top) vs. current (bottom):

image image

But it doesn't completely solve the issue, because cell values are still being truncated, see the first column. This leads to ambiguity since all of the values appear to be the same, and there's no way to see the full value in each cell.

I guess my question is why is this truncating happening at all? If we don't specify column widths, I thought the behavior is that the columns should take up as much width as they need to fit the content, especially given that the dataframe already has horizontal scrolling, so there's no need for columns to truncate the inner values to fit some arbitrary width.

Code to repro:

import gradio as gr
import pandas as pd

data = {
    "Name": ["test-run-v1", "test-run-v2", "test-run-v3"],
    "Username": ["abidlabs_user1", "abidlabs_user2", "abidlabs_user3"],
    "Created": ["about 30 minutes ago", "about 30 minutes ago", "about 30 minutes ago"],
    "epoch": [20, 20, 20],
    "learning_rate": [0.001, 0.001, 0.001],
    "batch_size": [32, 32, 32],
    "max_position_embeddings": [32768, 32768, 32768],
    "hidden_size": [896, 896, 896],
    "intermediate_size": [4864, 4864, 4864],
    "optimizer": ["adam with warmup schedule", "adam with warmup schedule", "adam with warmup schedule"],
    "dataset": ["custom-text-dataset-v1", "custom-text-dataset-v1", "custom-text-dataset-v1"],
    "status": ["running (ETA ~2h)", "completed successfully", "failed at step 1200"],
}

df = pd.DataFrame(data)

def show_table():
    return df

with gr.Blocks() as demo:
    gr.Markdown("## Experiment Runs Overview")
    gr.Dataframe(
        value=show_table(),
        interactive=False,
        label="Training Configurations and Status",
        truncate_headers=False
    )

demo.launch()

@pngwn pngwn changed the title Add truncate_headers param to improve header text control Add truncate_headers parameter to Dataframe to improve header text control Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gr.Dataframe automatically truncates long column headers and cell values

4 participants