Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Feb 18, 2025

Describe your changes

Configures st.dataframe and st.data_editor to use use_container_width=True as default (stretch the full container width) if the user does not provide a width explicitly.

Testing Plan

  • Update e2e tests.
  • Added unit tests.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@lukasmasuch lukasmasuch changed the title Set use_container_width=True by default for st.dataframe and st.data_editor [WIP] Set use_container_width=True by default for st.dataframe and st.data_editor Feb 18, 2025
@lukasmasuch lukasmasuch marked this pull request as draft February 18, 2025 17:31
@sfc-gh-lmasuch sfc-gh-lmasuch added security-assessment-completed Security assessment has been completed for PR impact:users PR changes affect end users change:feature PR contains new feature or enhancement implementation labels Feb 18, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review February 24, 2025 20:50
@lukasmasuch lukasmasuch changed the title [WIP] Set use_container_width=True by default for st.dataframe and st.data_editor Set use_container_width=True by default for st.dataframe and st.data_editor Feb 24, 2025
@sfc-gh-lwilby
Copy link
Collaborator

I noticed the playwright snapshots for categorical_index have the index slightly smaller, is this due to adding the pinned column option? I agree it looks better that way.



st.header("Hide index parameter:")
st.dataframe(df, hide_index=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to pin the width for some of these tests instead of setting use_container_width=False?

I guess use_container_width=False will be replaced by width="content". Do you have a sense of which of these three is the most commonly used?

Copy link
Collaborator Author

@lukasmasuch lukasmasuch Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to pin the width for some of these tests instead of setting use_container_width=False?

We have some dedicated tests for width=pixels here: https://github.com/streamlit/streamlit/blob/develop/e2e_playwright/st_dataframe_dimensions.py But from our adoption data, its not used a lot so I think its better to mostly test with use_container_width=True/False.

I guess use_container_width=False will be replaced by width="content". Do you have a sense of which of these three is the most commonly used?

We hope that width="stretch" would be the preferred option in most cases. But the data will eventually show us how many users are switching it to False / content again.

st.dataframe(df)
st.dataframe(df, use_container_width=False)
st.dataframe(df, 250, 150)
st.dataframe(df, width=250)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know there is this test as well, I was just thinking it looks a bit odd to override the default setting in so many tests.

@sfc-gh-lwilby
Copy link
Collaborator

Just curious, we do expect width="stretch" (or whatever the final name is), to be the most commonly used option by users? I was a bit surprised to see so many tests overriding it.

@lukasmasuch
Copy link
Collaborator Author

Just curious, we do expect width="stretch" (or whatever the final name is), to be the most commonly used option by users?

Yes, the assumption is that stretch is the more commonly preferred setting for DataFrame.

I was a bit surprised to see so many tests overriding it.

Some of the tests overwrite it because we need a deterministic column width for our interactive dataframe e2e tests. For other tests, I just used use_container_width=False to minimize the number of snapshot changes. We have enough tests with default value and use_container_width=True to ensure that these parameters work fine. Also, it's slightly preferred to test with smaller screenshots than larger ones in our CI pipeline since our threshold might lead to ignoring small visual changes on large snapshots.

@lukasmasuch
Copy link
Collaborator Author

I noticed the playwright snapshots for categorical_index have the index slightly smaller, is this due to adding the pinned column option? I agree it looks better that way.

We decided not to "grow" pinned/index columns since they look a bit better visually. This means that pinned columns will be sized based on their content, and other columns will take up the available space.

@sfc-gh-lwilby
Copy link
Collaborator

I was a bit surprised to see so many tests overriding it.

Some of the tests overwrite it because we need a deterministic column width for our interactive dataframe e2e tests. For other tests, I just used use_container_width=False to minimize the number of snapshot changes. We have enough tests with default value and use_container_width=True to ensure that these parameters work fine. Also, it's slightly preferred to test with smaller screenshots than larger ones in our CI pipeline since our threshold might lead to ignoring small visual changes on large snapshots.

That makes sense. I'm not so much concerned about test coverage, it would just be nice not to have all the overrides and have most tests use the default behaviour. But it's not a bit concern and keeping the snapshots small is a good counter reasoning.

@sfc-gh-lwilby
Copy link
Collaborator

I noticed the playwright snapshots for categorical_index have the index slightly smaller, is this due to adding the pinned column option? I agree it looks better that way.

We decided not to "grow" pinned/index columns since they look a bit better visually. This means that pinned columns will be sized based on their content, and other columns will take up the available space.

I noticed this in the prototype as well, I agree it looks funny when the index column grows large.

@lukasmasuch lukasmasuch enabled auto-merge (squash) February 25, 2025 12:48
@lukasmasuch lukasmasuch merged commit b0a7a95 into develop Feb 25, 2025
32 checks passed
@lukasmasuch lukasmasuch deleted the feature/set-use-container-width-true-for-dataframe branch March 5, 2025 18:49
@rsheftel
Copy link

This change dramatically changes the look of all of my existing streamlits. I respect the desire to move to this new default, but it is causing me to have to add "set_container_width=False" everywhere. it would be nice to add an option to the config file to set the default for this option.

@sfc-gh-lwilby
Copy link
Collaborator

This change dramatically changes the look of all of my existing streamlits. I respect the desire to move to this new default, but it is causing me to have to add "set_container_width=False" everywhere. it would be nice to add an option to the config file to set the default for this option.

@rsheftel that's an interesting idea -- can you file an issue (enhancement)? We are currently working on providing more layout options. cc @jrieke

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants