Skip to content
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

Altair Grouped Barchart with st.altair_chart(use_container_width=True) creates multiple charts instead of one single grouped chart #8531

Open
3 of 4 tasks
sapphire008 opened this issue Apr 18, 2024 · 1 comment
Labels
feature:st.altair_chart status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working

Comments

@sapphire008
Copy link

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

When creating a grouped bar chart using Altair and render it with st.altair_chart(fig, use_container_width=True), multiple charts for each group, rather than a combined single chart, is created. See screenshot attached. Code to reproduce is also attached.

Screenshot 2024-04-18 at 5 42 59 PM

Reproducible Code Example

import streamlit as st
import altair as alt
from vega_datasets import data

def make_plot():
    source = data.barley()

    fig = alt.Chart(source).mark_bar().encode(
        x='year:O',
        y='sum(yield):Q',
        color='year:N',
        column='site:N'
    )
    return fig

def main():
    fig = make_plot()
    # This is okay
    st.markdown("This is okay")
    st.altair_chart(fig)
    
    # This creates multiple charts instead of one chart
    st.markdown("This creates multiple chart, each for a 'site'/column value")
    with st.container():
        st.altair_chart(fig, use_container_width=True)


if __name__ == '__main__':
    main()

Steps To Reproduce

  1. Save the above code in a script, and run streamlit run app.py.

Expected Behavior

Expecting a single grouped bar chart is created and spans over the width of the container, rather than having multiple charts created when rendering with st.altair_chart(fig, use_container_width=True).

Current Behavior

Current behavior is: multiple charts for each column/group is created.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.33.0
  • Python version: 3.11.7
  • Operating System: MacOS 14.4
  • Browser: Chrome

Additional Information

No response

@sapphire008 sapphire008 added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Apr 18, 2024
Copy link

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

@sapphire008 sapphire008 changed the title Altair Grouped Barchart with st.altair_chart(use_container_width=True) creates multiple chart instead of one single grouped chart Altair Grouped Barchart with st.altair_chart(use_container_width=True) creates multiple charts instead of one single grouped chart Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.altair_chart status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants