Dash DataTable - Downloading Selected Rows

Hi,
I think you are already there! Not sure if I miss anything but the best way for me would be to create a df from your currently displayed table rows and then do a simple df filtering based on your selected row indices, then save the df to CSV etc.

Quick try for callback would be:

@app.callback(Output('save-table-textbox', 'children'),
             [Input('save-table-button', 'n_clicks')],
             [State('table', 'rows'),
              State('table', 'selected_row_indices')]
              )

def save_current_table(savebutton, tablerows, selected_row_indices):

    table_df = pd.DataFrame(tablerows) #convert current rows into df

    if selected_row_indices:
        table_df = table_df.loc[selected_row_indices] #filter according to selected rows

    if savebutton:
        table_df.to_csv(filename)
        return "Current table saved."
1 Like