Skip to content

[AdvancedLayouts] Add width to st.altair_chart#12608

Merged
sfc-gh-lwilby merged 2 commits intodevelopfrom
feature/vega-charts-width
Sep 24, 2025
Merged

[AdvancedLayouts] Add width to st.altair_chart#12608
sfc-gh-lwilby merged 2 commits intodevelopfrom
feature/vega-charts-width

Conversation

@sfc-gh-lwilby
Copy link
Copy Markdown
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby commented Sep 23, 2025

Describe your changes

Adds a new width parameter to st.altair_chart using the Width type system ("stretch", "content", or pixel values) for consistency with other chart elements.

Changes Made:

  • Added new parameter: Added width: Width | None = None parameter
  • Defaults to stretch in most cases, but for certain charts (e.g. facet) the default is content
  • Enhanced parameter validation: Validates width parameter with appropriate error messages

GitHub Issue Link (if applicable)

Testing Plan

  • Unit Tests (Python) - New width parameter functionality.
  • E2E Tests - Covered by st_vega_lite_charts_width, st_altair_chart and one new test of fixed width.
  • Manual verification of altair chart apps.

Screenshots/Demos:

Screenshot 2025-09-23 at 2 47 18 PM

Additional Notes:

This extends the AdvancedLayouts initiative by adding width support to st.altair_chart, bringing it in line with other chart elements that support the Width type system.

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.


Contribution License Agreement

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

@sfc-gh-lwilby sfc-gh-lwilby added security-assessment-completed change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Sep 23, 2025
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Sep 23, 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
Copy Markdown
Contributor

github-actions bot commented Sep 23, 2025

✅ PR preview is ready!

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

@sfc-gh-lwilby sfc-gh-lwilby changed the title [AdvancedLayouts] Add width to st.altair_chart [WIP][AdvancedLayouts] Add width to st.altair_chart Sep 23, 2025
@sfc-gh-lwilby sfc-gh-lwilby changed the title [WIP][AdvancedLayouts] Add width to st.altair_chart [AdvancedLayouts] Add width to st.altair_chart Sep 23, 2025
Copy link
Copy Markdown
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 a new width parameter to st.altair_chart that follows the standardized Width type system ("stretch", "content", or pixel values), while also beginning the deprecation process for the existing use_container_width parameter.

Key changes include:

  • Addition of the new width parameter with automatic defaults based on chart type
  • Deprecation warnings and migration logic for use_container_width
  • Comprehensive test coverage for the new width functionality

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/streamlit/elements/vega_charts.py Adds width parameter, deprecation handling, and documentation for st.altair_chart
lib/tests/streamlit/elements/vega_charts_test.py Comprehensive test suite for width parameter functionality and deprecation behavior
e2e_playwright/st_vega_charts_width.py Adds E2E test case for altair chart with fixed width
e2e_playwright/st_vega_charts_width_test.py Updates test expectations to include new altair chart test case
e2e_playwright/st_altair_chart_title.py Migrates from use_container_width to new width parameter
e2e_playwright/st_altair_chart_basic_select.py Migrates from use_container_width to new width parameter
e2e_playwright/st_altair_chart.py Migrates from use_container_width to new width parameter

.gitignore Outdated
**/uber-raw-data-sep14.csv

# Prompts directory
Prompts/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: can this better match the existing naming convention of our folders?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also out of curiosity, what is going in here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This wasn't supposed to be included in this PR. This is just a folder I have been keeping some prompt files in locally. Separate from this PR I agree we should align on a directory structure for this kind of thing. I don't have anything I want to check in currently, but we should have the folder with a .gitignore rule.

@sfc-gh-lwilby sfc-gh-lwilby merged commit b4d5911 into develop Sep 24, 2025
38 of 39 checks passed
@sfc-gh-lwilby sfc-gh-lwilby deleted the feature/vega-charts-width branch September 24, 2025 15:43
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants