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

Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Aug 15, 2025

Describe your changes

Adds support for format_func to st.column_config.SelectboxColumn which 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.

st.dataframe(
    pd.DataFrame({"col_0": [1, 2, 3, None]}),
    column_config={
        "col_0": st.column_config.SelectboxColumn(
            "Selectbox column",
            options=[1, 2, 3, 4, 5],
            format_func=lambda x: f"Option {x}",
        )
    },
)

GitHub Issue Link (if applicable)

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.

@snyk-io
Copy link
Contributor

snyk-io bot commented Aug 15, 2025

🎉 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)

@github-actions
Copy link
Contributor

github-actions bot commented Aug 15, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12232/streamlit-1.48.1-py3-none-any.whl
🕹️ Preview app pr-12232.streamlit.app (☁️ Deploy here if not accessible)

@sfc-gh-lmasuch sfc-gh-lmasuch added change:feature PR contains new feature or enhancement implementation security-assessment-completed Security assessment has been completed for PR impact:users PR changes affect end users labels Aug 15, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review August 15, 2025 17:20
@lukasmasuch lukasmasuch requested a review from Copilot August 15, 2025 17:20
Copy link
Contributor

Copilot AI left a 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_func parameter to Python SelectboxColumn with 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
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

@sfc-gh-nbellante sfc-gh-nbellante left a 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

@lukasmasuch lukasmasuch enabled auto-merge (squash) August 18, 2025 11:44
@lukasmasuch lukasmasuch merged commit cd499bb into develop Aug 18, 2025
36 of 37 checks passed
@lukasmasuch lukasmasuch deleted the feature/selectbox-format-func branch August 18, 2025 13:34
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.

st.column_config.SelectboxColumn: Extend config with dict mapping to separate backend and user value representation.

4 participants