Is there a way to specify column width for dataframe/table

I need to show a table containing a mix of numeric fields and (possibly wrapped) text sentences. Currently the dataframe and table methods seem to ignore bit pandas and Styler width settings and truncate at 30 characters. Is there a way to change this?
Thanks

1 Like

Hi @knorthover

Streamlit can draw dataframes in two different ways:

  1. With st.dataframe(df), to show a scrollable / sortable / interactive table. This is what st.write and magic use behind the scenes.
  2. With st.table(df), to show a static table.

Both methods support dataframe Stylers, but as you found out they only support a subset of styles: only colors and display values. Which means we today ignore width settings in Stylers.

(BTW, I created a feature request for you here)

That said, between st.dataframe and st.table, only the former truncates columns at all. That is, st.table shows tables in their entirety: no truncation, no scrolling, just the whole table.

So a work-around for you would be to use st.table for now.

1 Like

Great, thank you. I was able to use st.table with some of the Styler options to get very close to what I want. I’m pretty sure our users will be happy (showtime on Monday).

1 Like

We use tables extensively in our dashboards and unfortunately our tables tend to be pretty large. Some customization options for st.dataframe and st.table would be highly appreciated. Cell width, height, borders and text wrapping would be great!

Absolutely agree! We’re tracking that in this issue and I added in your specifications as well. If you think of anything else you’d like please feel free to add to the issue:

2 Likes

Hi @wotaskd and @knorthover

For now a workaround could also be to use the plotly table. You can use all the customization it has.

There is an example in the gallery at awesome-Streamlit.org. You find the example and code under the “Table experiments” app

1 Like