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

Merged
merged 82 commits into from
Mar 10, 2025
Merged

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
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

@hysts
Copy link
Collaborator

hysts commented Mar 7, 2025

The current behavior doesn't seem to work well with adding/deleting columns.

It depends on the use case, but for example, even if there is a column that the app developer wants to prevent users from changing, users can make it editable by adding a new column to its left.

import gradio as gr
import numpy as np

with gr.Blocks() as demo:
    gr.Dataframe(value=np.arange(15).reshape(3, 5), static_columns=[1], interactive=True)
demo.launch()
0.mp4

@abidlabs
Copy link
Member

abidlabs commented Mar 7, 2025

great catch @hysts. Perhaps we'll need to add some logic that if static_columns is specified, then col_count is fixed and columns cannot be inserted/deleted at all

Base automatically changed from improve-df to main March 7, 2025 10:52
@hannahblair
Copy link
Collaborator Author

hmm I see. alternatively, we could remove the specified static column from static_columns if it's removed. but adding columns will also cause some confusing behaviour. i've updated the PR to set it to "fixed" if static columns are specified. thanks for reviewing @hysts!

@abidlabs
Copy link
Member

abidlabs commented Mar 7, 2025

I reran @hysts's repro and I'm seeing a different issue with cell / header alignment being off:

image
import gradio as gr
import numpy as np

with gr.Blocks() as demo:
    gr.Dataframe(value=np.arange(15).reshape(3, 5), static_columns=[1], interactive=True)
demo.launch()

@hannahblair
Copy link
Collaborator Author

@abidlabs fixed! my bad python code was the culprit

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

Nice @hannahblair lgtm! We could consider adding a padlock symbol just in the header cell to designate a static column, but we don't have to do it now (or ever if it's a bad ui)

@hannahblair
Copy link
Collaborator Author

hannahblair commented Mar 10, 2025

@abidlabs agreed, I'm happy with this now!

Screenshot 2025-03-10 at 15 30 15

@abidlabs
Copy link
Member

@abidlabs agreed, I'm happy with this now!

Nice!

@hannahblair hannahblair merged commit c44b8f4 into main Mar 10, 2025
23 checks passed
@hannahblair hannahblair deleted the df-static-cols branch March 10, 2025 19:10
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
4 participants