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

Add static_columns param for interactive dataframes #10734

Open
wants to merge 12 commits into
base: improve-df
Choose a base branch
from

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented Mar 5, 2025

Description

Adds a static_columns param, which takes a list of ints or strs to reference the columns. The use of static rows does feel potentially quite niche so we'll see if there are any requests for that.

Closes: #2020

🎯 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

@hannahblair hannahblair changed the base branch from main to improve-df March 5, 2025 17:50
@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Mar 5, 2025

🪼 branch checks and previews

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

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/8f7467465a04a063e8a2910529562be6c836897a/gradio-5.20.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/8f7467465a04a063e8a2910529562be6c836897a/gradio-client-1.13.0.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/8f7467465a04a063e8a2910529562be6c836897a/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/dataframe minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Add static_columns param for interactive dataframes

Maintainers or the PR author can modify the PR title to modify this entry.

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 March 5, 2025 21:58
@hannahblair
Copy link
Collaborator Author

hannahblair commented Mar 6, 2025

I am interested to know whether we need a little UI/UX touch to indicate the column isn't editable. I tried a not-allowed cursor but it's a bit too aggressive.

@abidlabs
Copy link
Member

abidlabs commented Mar 6, 2025

Thanks @hannahblair! LGTM with two minor suggestions:

  • I do think some kind of visual feedback would be helpful. Perhaps we can apply a slight background shade or opacity to cells that are static?

Adds a static_columns param, which takes a list of ints or strs to reference the columns

  • I see the ergonomic benefit of being able to refer to columns by either the ints or strs, but I think it may lead to some ambiguity since we create 1-indexed headers by default. For example, if I adapt the matrix_transpose demo to add a static column:
import numpy as np

import gradio as gr

def transpose(matrix):
    return matrix.T

demo = gr.Interface(
    transpose,
    gr.Dataframe(type="numpy", datatype="number", row_count=5, col_count=3, show_fullscreen_button=True, static_columns=[1]),
    "numpy",
    examples=[
        [np.zeros((3, 3)).tolist()],
        [np.ones((2, 2)).tolist()],
        [np.random.randint(0, 10, (3, 10)).tolist()],
        [np.random.randint(0, 10, (10, 3)).tolist()],
        [np.random.randint(0, 10, (10, 10)).tolist()],
    ],
    cache_examples=False
)

if __name__ == "__main__":
    demo.launch()

the developer may be referring to either the column whose header is 1 or the second column in the dataframe. To avoid ambiguity, perhaps we should only refer to columns by numerical indices.

@abidlabs
Copy link
Member

abidlabs commented Mar 6, 2025

While I was testing this, I noticed an strange but unrelated issue which is that when we create column headers automatically, they can be either 0-indexed or 1-indexed (I think depending on whether the dataframe initially has values):

import gradio as gr
import pandas as pd


data = [[25, 45, 35],
[88, 92, 95]]

df = pd.DataFrame(data)


with gr.Blocks() as blocks:
    m = gr.Dataframe()
    m = gr.Dataframe(df)


blocks.launch()
image

@hannahblair
Copy link
Collaborator Author

@abidlabs update the datatype!

i also think a fairly straightforward disabled indicator is actually the cursor not-allowed on the actual input element. so right now clicking on the cell will show the input, but with this cursor change the input is disabled and the cursor is not-allowed. here's a visual:

Kapture 2025-03-06 at 17 28 58

@hannahblair
Copy link
Collaborator Author

I was thinking a padlock somewhere in the cell but it just looks too crowded.

@abidlabs
Copy link
Member

abidlabs commented Mar 6, 2025

sgtm

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.

Restrict the scope of interactivity for gr.Dataframe
3 participants