Black Lives Matter. Please consider donating to Black Girls Code today.

Dash Datatable - Limiting the number of selected rows

I’m trying to limit the number of rows the user can select in a Datatable. However, it seems that auto-callbacks like this one are impossible (here, with a limit of 20):

@app.callback(Output('table', 'selected_row_indices'),
              [Input('table', 'selected_row_indices')])
def limit_row_indices(indices):
    if indices is not None:
        if len(indices>20):
            return indices[:20]

I understand that this prevents entering into an infinite loop. But is there a working solution to limit the number of rows selected by the user?


I know that this is long dead most likely but I am trying to accomplish this exact thing right now using a multi select data table that only allows a single selection at any time