Repository: streamlit/streamlit
File: e2e_playwright/st_dataframe_dimensions.py (Python)

Code before:
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import pandas as pd

import streamlit as st

# Explicitly seed the RNG for deterministic results
np.random.seed(0)
data = np.random.randn(100, 100)

df = pd.DataFrame(data)
st.dataframe(df, width="content")
st.dataframe(df, 250, 150)
st.dataframe(df, width=250)
st.dataframe(df, height=150, width="content")
st.dataframe(df, 5000, 5000)
st.dataframe(df, width="stretch")

small_df = pd.DataFrame(np.random.randn(100, 3))
st.dataframe(small_df, width=500)
st.dataframe(small_df)
st.dataframe(small_df, width="stretch")
st.dataframe(small_df, width=200)
st.dataframe(small_df, width="stretch")
st.dataframe(small_df, width="content")

one_col_df = pd.DataFrame(np.random.randn(100, 1))
st.dataframe(one_col_df, width="stretch")

if st.button("Resize dataframe"):
    st.dataframe(small_df, width=400, height=200)
else:
    st.dataframe(small_df, width=200, height=100)

short_dataframe = pd.DataFrame(np.random.randn(4, 4))
st.dataframe(short_dataframe, width="stretch", key="stretch_dataframe")
st.dataframe(short_dataframe, width="content", key="content_dataframe")
st.dataframe(short_dataframe, width=400, height=300, key="fixed_dimensions_dataframe")

st.write("Dataframe with height='stretch' (in 400px container):")
with st.container(border=True, key="test_height_stretch", height=400):
    st.dataframe(short_dataframe, height="stretch", key="stretch_height_dataframe")

st.write("Dataframe with height='stretch' outside of a container:")
st.dataframe(
    short_dataframe, height="stretch", key="stretch_height_dataframe_outside_container"
)


Review comment (suggestion):
I think I left these ones in to make sure this still works until we fully deprecate `use_container_width`. We already have tests for `width="stretch"` and fixed width. 

Code after:
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import pandas as pd

import streamlit as st

# Explicitly seed the RNG for deterministic results
np.random.seed(0)
data = np.random.randn(100, 100)

df = pd.DataFrame(data)
st.dataframe(df, width="content")
st.dataframe(df, 250, 150)
st.dataframe(df, width=250)
st.dataframe(df, height=150, width="content")
st.dataframe(df, 5000, 5000)
st.dataframe(df, width="stretch")

small_df = pd.DataFrame(np.random.randn(100, 3))
st.dataframe(small_df, width=500)
st.dataframe(small_df)
st.dataframe(small_df, width=200, use_container_width=True)
st.dataframe(small_df, width=200, use_container_width=False)
st.dataframe(small_df, width="stretch")
st.dataframe(small_df, width="content")

one_col_df = pd.DataFrame(np.random.randn(100, 1))
st.dataframe(one_col_df, width="stretch")

if st.button("Resize dataframe"):
    st.dataframe(small_df, width=400, height=200)
else:
    st.dataframe(small_df, width=200, height=100)

short_dataframe = pd.DataFrame(np.random.randn(4, 4))
st.dataframe(short_dataframe, width="stretch", key="stretch_dataframe")
st.dataframe(short_dataframe, width="content", key="content_dataframe")
st.dataframe(short_dataframe, width=400, height=300, key="fixed_dimensions_dataframe")

st.write("Dataframe with height='stretch' (in 400px container):")
with st.container(border=True, key="test_height_stretch", height=400):
    st.dataframe(short_dataframe, height="stretch", key="stretch_height_dataframe")

st.write("Dataframe with height='stretch' outside of a container:")
st.dataframe(
    short_dataframe, height="stretch", key="stretch_height_dataframe_outside_container"
)