lufthansa747
lufthansa747

Reputation: 2061

Plotly Dash: Select Rows in DataTable as Callback Output + Filter

I have a DataTable with some line graphs displaying the values. I want to implement it such that clicking a single point in the graph will filter the table data to that trace and select the row which the user specifically clicked on. I have used the pandas index and created a 'id' row so that each row has a unique id associated with it. This is my callback i am trying to use

@app.callback(
    [Output("datatable-rfStats", "data"), Output("datatable-rfStats", "selected_row_ids")],
    [Input("dev-lvl-clear", "n_clicks")] + plot_dev_lvl_filter_inputs
)
return filtered_df.sort_values(by=['lastUpdated']).to_dict('records'), [row_id]

I have the DataTable setup for multi selectable rows. When i click on the line graph the DataTable filters the data correctly but does not select the requested row. I have debugged and confirmed that the 'row_id' is in the set of rows being returned. Not sure if i'm doing something wrong or if the multiple outputs doesnt work as i expected.

Note: plot_dev_lvl_filter_inputs is just an array which i am dynamically filling with the Inputs() for the charts I am displaying. I can go into more depth on this setup if its relevant but all the graph inputs work perfectly so I don't think this is the issue

Upvotes: 1

Views: 5360

Answers (1)

Soerendip
Soerendip

Reputation: 9148

Try this:

@app.callback(
    [Output("datatable-rfStats", "data"), Output("datatable-rfStats", "selected_rows")],
    [Input("dev-lvl-clear", "n_clicks")] + plot_dev_lvl_filter_inputs
)
return filtered_df.sort_values(by=['lastUpdated']).to_dict('records'), [row_id]

Instead of setting selected_row_ids use selected_rows.

Upvotes: 2

Related Questions