Hi there,
I am new in Dash applications and I wish to create a AG Grid which is sorted by the values of a dataframe column in ascending or descending order. Here are the steps I am following:
- import a csv and convert it into a pandas dataframe (df).
- create a dropdown component that recognizes df’s columns labels (id = “dropdown”).
- create a radiobutton component that allows me to toggle between ascending/descending order (id = “radio_button”).
- create the callback:
@callback(
Output(component_id=“sorted-parameters-table”, component_property=“children”),
Input(component_id=“dropdown”, component_property=“value”),
Input(component_id=“radio_button”, component_property=“value”)
)
def update_output(sort_dropdown, sort_radio):
asc_order=False
if sort_radio==“Ascending”: asc_order = True
df_sorted = df.sort_values(by=sort_dropdown, ascending=asc_order)
grid = dag.AgGrid(
columnDefs=[{“field”: x} for x in df_sorted.columns],
rowData=df_sorted.to_dict(“records”),
dashGridOptions={“pagination”:True}
)
return grid
Here is my question:
- ideally I wouldn’t like the dag.AgGrid to be located inside the update_output method, but I don’t know what to use as a component_property for the Output @callback.
- Assuming that the dag.AgGrid stays inside the update_output method, why the following code does not show me the AgGrid? Any help/hints would be much appreciated.
Regards,
jm