-
Notifications
You must be signed in to change notification settings - Fork 4k
[AdvancedLayouts] Updates to st.image width/height and adding width/height to st.pyplot. #11952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
✅ PR preview is ready!
|
00359f5 to
4a5f1c6
Compare
c553530 to
eaf8ea0
Compare
📈 Frontend coverage change detectedThe frontend unit test (vitest) coverage has increased by 0.0300%
🎉 Great job on improving test coverage! |
📈 Python coverage change detectedThe Python unit test coverage has increased by 0.0243%
✅ Coverage change is within normal range. Coverage by files
|
45c0a47 to
8886561
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the image width system for st.image and st.pyplot as part of the AdvancedLayouts project. It introduces a new unified width configuration system that replaces the legacy WidthBehavior enum-based approach while maintaining backward compatibility. The main goal is to deprecate use_container_width in favor of a more flexible width parameter.
Key Changes:
- Introduces new
widthparameter for both st.image and st.pyplot supporting "content", "stretch", and pixel values - Begins deprecation of
use_container_widthwith warning messages and fallback behavior - Updates both backend and frontend to use new LayoutConfig system instead of legacy width behavior
Reviewed Changes
Copilot reviewed 17 out of 40 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| proto/streamlit/proto/Image.proto | Marks legacy width field as deprecated |
| lib/streamlit/elements/image.py | Adds new width parameter and deprecation handling for use_container_width |
| lib/streamlit/elements/pyplot.py | Adds width parameter to st.pyplot with deprecation logic |
| lib/streamlit/elements/lib/image_utils.py | Updates image processing to use LayoutConfig instead of WidthBehavior |
| frontend/lib/src/components/elements/ImageList/ImageList.tsx | Implements new width configuration system with legacy fallback |
| e2e_playwright/st_image.py | Adds test cases for new width parameter |
| e2e_playwright/st_pyplot.py | Adds test cases for new width parameter |
lib/streamlit/elements/pyplot.py
Outdated
| ) | ||
|
|
||
| if width == "stretch": | ||
| width = "stretch" if use_container_width else "content" |
Copilot
AI
Aug 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition if width == "stretch": will always be true since width defaults to "stretch" when use_container_width is not None. This means the deprecation logic will override the width parameter regardless of the use_container_width value. The condition should check the use_container_width value instead.
| width = "stretch" if use_container_width else "content" | |
| width = "stretch" if use_container_width else "content" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic is actually wrong. We should override the width with use_container_width.
Although this description from copilot is not correct.
sfc-gh-bnisco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Co-authored-by: Bob Nisco <[email protected]>
Describe your changes
This PR is part of the [AdvancedLayouts] project and updates
widthonst.imageto use the new width style and addswidthtost.pyplot.This PR also begins the process of deprecating use_container_width. The default is updated to None, and width will be used instead. If the user explicitly passes a value for use_container_width then that will take precedence. use_container_width=True is equivalent to width="stretch" and use_container_width=False is equivalent to width="content". The user will be given a warning and suggestion to use width instead. We will remove use_container_width after 12-31-2025`.
GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.