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

Skip to content

Conversation

@jrieke
Copy link
Collaborator

@jrieke jrieke commented Dec 21, 2024

Describe your changes

This PR makes the following commands have use_container_width=True by default:

  • st.dataframe -> Decided to do the dataframe changes in a separate PR, see discussion below.
  • st.data_editor
  • st.bokeh_chart
  • st.plotly_chart
  • st.pydeck_chart

The following two commands get use_container_width=None by default, which is internally set to True for most cases except for some multi-view charts that don't work well with use_container_width=True (see #9091):

  • st.altair_chart
  • st.vega_lite_chart

And we're keeping the default of use_container_width=False for the following commands:

  • st.image
  • st.button
  • st.graphviz_chart

GitHub Issue Link (if applicable)

Testing Plan

Just updated existing snapshots and one unit test. For a few tests (e.g. that click on a specific location), I simply set use_container_width=False to keep the current behavior. For others, I just went with the new default behavior and updated the snapshots. Note that this updates a ton of snapshots (especially for dataframes). If we don't want that, we can also set use_container_width=False for all of these tests. But I think it makes sense to just use the default value as much as possible.


Contribution License Agreement

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

@jrieke jrieke 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 Dec 21, 2024
@jrieke jrieke changed the title [WIP] Set use_container_width=True by default [WIP] Set use_container_width=True by default for more elements Dec 21, 2024
@jrieke jrieke changed the title [WIP] Set use_container_width=True by default for more elements Set use_container_width=True by default for more elements Dec 21, 2024
@jrieke jrieke marked this pull request as ready for review December 21, 2024 23:53
Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

The changes related to the chart command look good 👍

For dataframe, it looks a bit off sometimes if the table has very few columns.
Maybe we could also introduce use_container_width = None to auto-activate if > x visible columns. Or find a way to better auto-size range index columns. Instead of using grow for those columns, we could probably calculate a perfect size based on the range index metadata. Or we only apply grow to all non-pinnend columns, this would probably make it look a bit nicer. E.g.:

image

vs

image

Another aspect to think through is how we want this to behave in Notebooks output. Maybe we want to set use_container_width=False for dataframe in st.write?

To speed up merging this, it might make sense to split out the changes for dataframe/data_editor into a dedicated PR.

@jrieke
Copy link
Collaborator Author

jrieke commented Dec 23, 2024

Yeah good comment. I removed the dataframe changes from this PR for now, can you aprove @lukasmasuch?

Or we only apply grow to all non-pinnend columns, this would probably make it look a bit nicer.

I think that's the solution I'd prefer, can you give me a pointer where I'd change that? Then I can play around with it.

Another aspect to think through is how we want this to behave in Notebooks output. Maybe we want to set use_container_width=False for dataframe in st.write?

I think it's nicer if st.write also uses use_container_width=True. That was even one of the main motivations behind changing the default, see e.g. #7625 (and I also heard from a few users that they were annoyed by this). Plus, I think it's nice if both commands are consistent, so that your app doesn't change if you replace st.write with st.dataframe.

@jrieke jrieke changed the title Set use_container_width=True by default for more elements Set use_container_width=True by default for charts Dec 23, 2024
Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@lukasmasuch
Copy link
Collaborator

I think that's the solution I'd prefer, can you give me a pointer where I'd change that? Then I can play around with it.

Probably as simple as changing:

...(column.isStretched && {
grow: column.isIndex ? 1 : 3,
}),

to

    ...(column.isStretched &&
      !column.isPinned && {
        grow: 1,
      }),

@jrieke jrieke merged commit 833efa9 into develop Dec 23, 2024
32 checks passed
@jrieke jrieke deleted the feature/use-container-width-default branch December 23, 2024 13:35
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
## Describe your changes

This PR makes the following commands have `use_container_width=True` by
default:

- ~~st.dataframe~~ -> Decided to do the dataframe changes in a separate
PR, see discussion below.
- ~~st.data_editor~~
- st.bokeh_chart
- st.plotly_chart
- st.pydeck_chart

The following two commands get `use_container_width=None` by default,
which is internally set to `True` for most cases except for some
multi-view charts that don't work well with `use_container_width=True`
(see streamlit#9091):

- st.altair_chart
- st.vega_lite_chart

And we're keeping the default of `use_container_width=False` for the
following commands:

- st.image
- st.button
- st.graphviz_chart

## GitHub Issue Link (if applicable)

## Testing Plan

Just updated existing snapshots and one unit test. ~~For a few tests
(e.g. that click on a specific location), I simply set
`use_container_width=False` to keep the current behavior. For others, I
just went with the new default behavior and updated the snapshots. Note
that this updates a ton of snapshots (especially for dataframes). If we
don't want that, we can also set `use_container_width=False` for all of
these tests. But I think it makes sense to just use the default value as
much as possible.~~

---

**Contribution License Agreement**

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

---------

Co-authored-by: Johannes Rieke <[email protected]>
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.

4 participants