-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
base: main
Are you sure you want to change the base?
Conversation
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. |
Thanks @hannahblair! LGTM with two minor suggestions:
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 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: |
I was thinking a padlock somewhere in the cell but it just looks too crowded. |
sgtm |
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 |
great catch @hysts. Perhaps we'll need to add some logic that if |
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! |
I reran @hysts's repro and I'm seeing a different issue with cell / header alignment being off: ![]() 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() |
@abidlabs fixed! my bad python code was the culprit |
There was a problem hiding this 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)
Description
Adds a
static_columns
param, which takes a list ofint
s orstr
s 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
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
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