You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Hi @q275343119, I'm not sure I understand the question, you are already sorting the dataframe and passing the result to the gr.DataFrame component, right? So it is already being displayed in the correct order? Are you trying to prevent users from being able to sort the gr.DataFrame by clicking on a different column?
Hi @q275343119, I'm not sure I understand the question, you are already sorting the dataframe and passing the result to the gr.DataFrame component, right? So it is already being displayed in the correct order? Are you trying to prevent users from being able to sort the gr.DataFrame by clicking on a different column?
Apologies, I didn't express myself clearly. I have attached the demo code for your reference:
importgradioasgrimportpandasaspd# Sample DataFramedata= {
"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 columndefsort_dataframe(df, column_name):
sorted_df=df.sort_values(by=column_name)
returnsorted_df# Gradio Interfacedefupdate_dataframe(column_name):
sorted_df=sort_dataframe(df, column_name)
returnsorted_dfiface=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.
The GIF is shown below:
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: