-
Notifications
You must be signed in to change notification settings - Fork 4k
Add format_func support to SelectboxColumn
#12232
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!
|
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 adds format_func support to st.column_config.SelectboxColumn, allowing users to customize the display of selectbox options while preserving the original values in the dataframe. When provided, the format function receives each raw option and returns a custom label for display.
Key changes:
- Added
format_funcparameter to PythonSelectboxColumnwith corresponding TypeScript support - Updated both Python and TypeScript logic to handle options as value/label pairs when format_func is used
- Enhanced test coverage for the new functionality
Reviewed Changes
Copilot reviewed 6 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/streamlit/elements/lib/column_types.py |
Added format_func parameter and processing logic to transform options into value/label pairs |
frontend/lib/src/components/widgets/DataFrame/columns/SelectboxColumn.ts |
Added SelectOption type and prepareOptions function to handle both primitive and object option formats |
lib/tests/streamlit/elements/lib/column_types_test.py |
Added unit test for format_func functionality |
frontend/lib/src/components/widgets/DataFrame/columns/SelectboxColumn.test.ts |
Added comprehensive tests for new option handling and prepareOptions function |
e2e_playwright/st_dataframe_config.py |
Added format_func example to e2e test app |
e2e_playwright/st_data_editor_config.py |
Added format_func example to e2e test app |
Comments suppressed due to low confidence (1)
| } | ||
|
|
||
| return options | ||
| .filter(opt => opt !== null && opt !== "") // ignore empty option if it exists |
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.
nit/q: is it expected that an undefined option can sneak through?
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.
Added it 👍 I believe it might not be possible to get a null here, but it also doesn't hurt if we include this in the check.
sfc-gh-nbellante
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.
Just that one nit/question
Describe your changes
Adds support for
format_functost.column_config.SelectboxColumnwhich allows to modify the display of selectbox options. It receives the raw option as an argument and should output the label to be shown for that option. This has no impact on the value that is inserted into the dataframe.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.