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

Copy and paste with Data Table (restricting new rows and columns)

Hello, we are using Dash and the Data Table component to build some workflow tools for heavy Excel users. Part of the workflow is copying data out of Excel and into a layout of various Data Tables in a Dash app. Out of the box, if a user copies a blob of cells in Excel and pastes into a Data Table, the Data Table expands to accommodate both rows and columns from the Excel source (assuming the Excel source is larger than the Data Table).

We’d like to keep the columns fixed in the Data Table, and just ignore any “extra columns” from the inbound Excel when pasting (we know the columns at runtime). We would however like to expand the number of rows in the Data Table as that is unknown at run time.

Any advice on controlling this paste-from-Excel behavior?

I had the same issue. It’s kinda cool that the table will automatically expand to accommodate the cut and paste contents, but when it adds new undefined columns to an existing table, it’s a little odd - especially since by default these columns are not deletable by the user.

One option is to delete the new columns in a callback. Another is to update the columns property in a callback to make the new columns deletable. That way, the user will be able to delete them, plus know that something went wrong with the copy and paste (rather than the data along with the new columns just disappearing)

There are probably other ways, but this worked for me.