To add a bit more context. I want to d/l selected rows from this example. If I filter or resort the dash.datatable, the indexing (selected_row_indices) is updated as it should. However, I don’t have a way to subset this from the original dataframe.
Is there anyway to convert the dash.datatable to a dataframe? That way I can recreate the data as shown in the dash.datatable and have the correct indexing.
The specific code with callback is below.
def filter_data(selected_row_indices):
dff = DF_GAPMINDER.iloc[selected_row_indices]
return dff
@app.callback(
dash.dependencies.Output('download-link', 'href'),
[dash.dependencies.Input('datatable-gapminder', 'selected_row_indices')])
def update_download_link(selected_row_indices):
dff = filter_data(selected_row_indices)
csv_string = dff.to_csv(index=False, encoding='utf-8')
csv_string = "data:text/csv;charset=utf-8," + urllib.parse.quote(csv_string)
return csv_string