In the data_editor component, there’s a parameter called num_rows, which I can set to "dynamic". Is there a way to set num_columns to "dynamic" as well?
In my case, I want both the rows and columns of the table to expand automatically when I paste data from the clipboard.
Currently, st.data_editor supports num_rows="dynamic" but not num_columns. Columns are fixed by the input DataFrame. If you want both rows and columns to expand when pasting data, you can preprocess the clipboard with pandas.read_clipboard() and feed the resulting DataFrame into st.data_editor. That way, new columns are included automatically.
This method would only work on the server side; it wouldn’t work on the client side.
You’re right — Streamlit runs server-side, so we can’t intercept clipboard events directly in the browser. But the method I shared still solves the client-side experience:
-
The user pastes data into
st.data_editorin code -
The app detects if the data has more columns
-
It rebuilds the table with those columns and re-renders
This happens on the server, but from the client’s perspective, it feels automatic. No code edits, no manual schema updates.
If you need true browser-side clipboard control, that’s outside Streamlit’s scope for now — but this pattern gives you dynamic column expansion without extra effort.
Maybe a third-party component can achieve this.Like “streamlit-excel-table”. I’ll try it.