streamlit / streamlit

Streamlit — A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
38.3k stars 3.33k forks source link

Support `use_container_width=False` in `st.table()` #10775

Open JosephMarinier opened 1 week ago

JosephMarinier commented 1 week ago

Checklist

Summary

I would like to have the option st.table(df, use_container_width=False).

Why?

I appreciate the use_container_width=False in st.dataframe() and I would like to have the option in st.table().

How?

No response

Additional Context

In the meantime, here is a workaround:

import pandas as pd
import streamlit as st

st.html("""
<style>
    div[data-testid="stElementContainer"]:nth-child(4) > div[data-testid="stTable"] {
        max-width: fit-content;
    }
</style>
""")

df = pd.DataFrame({"x": [0.1, 0.2, 0.3], "y": [0.4, 0.5, 0.6]})

st.code("st.table()")
st.table(df)
st.table(df)  # Equivalent of use_container_width=False done with the CSS above.
st.divider()
st.code("st.dataframe()")
st.dataframe(df)
st.dataframe(df, use_container_width=False)

Image

github-actions[bot] commented 1 week ago

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits