-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
When dataframe value is updated, sorts are not reset #10296
Comments
Hi @q275343119, I'm not sure I understand the question, you are already sorting the dataframe and passing the result to the cc @hannahblair for visibility |
Apologies, I didn't express myself clearly. I have attached the demo code for your reference: import gradio as gr
import pandas as pd
# Sample DataFrame
data = {
"Name": ["Alice", "Bob", "Charlie", "David"],
"Age": [25, 45, 35, 40],
"Score": [88, 92, 95, 85]
}
df = pd.DataFrame(data)
# Function to sort the DataFrame based on the selected column
def sort_dataframe(df, column_name):
sorted_df = df.sort_values(by=column_name)
return sorted_df
# Gradio Interface
def update_dataframe(column_name):
sorted_df = sort_dataframe(df, column_name)
return sorted_df
iface = gr.Interface(
fn=update_dataframe,
inputs=[gr.Dropdown(choices=df.columns.tolist(), label="Sort by")],
outputs=gr.DataFrame(),
live=True
)
iface.launch() Let me now describe my scenario. First, I select age from the dropdown to sort, then click on the header of name to sort by that column. After this, no matter whether I try to sort by age or score, it doesn't work as expected. |
I want users to be able to sort by clicking on the column headers as well as by selecting the sorting field through the dropdown menu. |
I see, I've renamed the issue so that we can tackle this! |
That's cool, thank you! |
My use case is as follows:
I want to control the sorting field of the table through a dropdown menu. Suppose I choose to sort based on col_1. I will first sort the DataFrame (df), then pass the sorted df to gr.Dataframe. However, if I click on another column header in the table to sort it, the sorting by the dropdown becomes meaningless. This is because, no matter how I sort the df, once it is passed to gr.Dataframe, it will sort according to the column header selected on the interface.
Is there a parameter in gr.Dataframe that allows controlling the sorting field and the order (ascending or descending)?
Additional Info: I am using Gradio version 4.20.0.
The text was updated successfully, but these errors were encountered: