-
Notifications
You must be signed in to change notification settings - Fork 4k
✨ Support "auto" as the new default for st.image's use_column_width
#2635
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
Spec from Thiago: Without going so far as completely rethinking how we do sizes, the least we could do is change `use_column_width` to accept three values: - `'auto'` : sets the image to its natural size, unless its width is greater than the column width. In which case it scales the image to fit the column width. - `True` or `'always'`: sets the image size to fit the column width. - `False` or `'never'`: sets the image to its natural size. Then we'd make `'auto'` the default. (The current default is `False`)
karriebear
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.
e2e/scripts/st_image.py
Outdated
|
|
||
| st.set_option("deprecation.showImageFormat", True) | ||
| img = np.repeat(0, 10000).reshape(100, 100) | ||
| img400 = np.repeat(0, 160000).reshape(400, 400) |
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 would make this 800 just to be safe. The width we use on cypress is 1366. If we divide by 3 it's 455 which is right on the cusp. There's probably margin/padding elsewhere that 400 could be large enough but I figure go big or go home!
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 1366 is actually the full screen width of Cypress, but on this test the 3 columns are further restricted by the 798px main column; in my testing the width of each of the beta_columns was about 222px (after padding and stuff), so 400 was more than enough.
That said, nothing wrong with 800 either, so I've updated it here!
lib/streamlit/elements/image.py
Outdated
| Image caption. If displaying multiple images, caption should be a | ||
| list of captions (one for each image). | ||
| width : int or None | ||
| Image width. None means use the image width. |
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.
Product side note, I feel like none should use column width but that's just me
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.
Oh -- I agreed, and width=None actually does default to use_column_width='auto', aka the image will use its natural width but not exceed the column.
I've update the docstring here, though it might still be a bit confusing. @asaini , feel free to reword this section!
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
use_column_widthuse_column_width
|
Verified that functionality looks good 👍 Minor question: As mentioned in the notion doc, are we issuing any deprecation warning? |
I don't think we should issue an in-app warning (eg the one that FileUploader had), as the changes to st.image defaults are not likely to affect a lot of users; I think showing an in-app warning would annoy creators/users a lot more than it'd help the few people who'd notice the changes. We should absolutely call it out in our changelog release notes, though! |
|
Changelog callout sounds good to me! |
* develop: ✨ Support "auto" as the new default for st.image's `use_column_width` (streamlit#2635) fix branch name in pr-preview (streamlit#2644) ♻️ Remove "_proto" from "exception_proto.py" (streamlit#2638) ♻️ Remove "_proto" from "media_proto.py" and "iframe_proto.py" (streamlit#2639) Refactor: remove "_proto" from "image_proto.py" (streamlit#2626) correct info on url shortening behavior (streamlit#2576) Set "overflow:visible" on st.expander (streamlit#2611) Revert "Revert "Add anchors to Markdown headers (streamlit#2513)"" Fix file uploader docs + change to getvalue (streamlit#2628) Update change log Update notices Up version to 0.75.0 Revert "Add anchors to Markdown headers (streamlit#2513)" Speed up Cypress tests (streamlit#2600) Remove "beta feature" notice on st.color_picker (streamlit#2625) Deflake multiselect snapshot test by waiting for stale-element (streamlit#2624) Rerender Maybe components when they're first disabled (streamlit#2617) Increase side padding to 5rem when app is in wide mode (streamlit#2613)
Spec from Thiago
Without going so far as completely rethinking how we do sizes, the least we could do is change
use_column_widthto accept three values:'auto': sets the image to its natural size, unless its width is greater than the column width. In which case it scales the image to fit the column width.Trueor'always': sets the image size to fit the column width.Falseor'never': sets the image to its natural size.Then we'd make
'auto'the default. (The current default isFalse)