[Python] Streamlit renders plotly barplot incorrectly when running from global install

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have a barplot with stacked bars that I render in a streamlit app.

    To add some context, I want to be able to pip install the wheel of my project on a different PC and then run it from Windows cmd and without creating a virtual environment every time.

    For better understanding, I created a minimally reproducible example.

    import streamlit as st
    import plotly.express as px
    import pandas as pd

    # this is needed to write_html correctly
    import plotly.io as pio
    pio.templates.default = "plotly"

    df = pd.DataFrame({
    'Fruit': ['Apples', 'Apples', 'Oranges', 'Oranges'],
    'Amount': [10, 15, 20, 25],
    'City': ['SF', 'NY', 'SF', 'NY']
    })

    fig = px.bar(df, x='Fruit', y='Amount', color='City')
    fig.update_layout(barmode='stack')

    print("SAVE IMAGE")
    fig.write_html("test.html")

    st.plotly_chart(fig)


    The saved html looks something like this:

    [​IMG]

    That's also what it looks like when I use the streamlit installed in a virtual environment:

    .\.venv\Scripts\streamlit.exe run .\streamlit_test.py

    However, when I run it from the globally installed streamlit, the bars are not stacked.

    C:\Users\my_username\AppData\Local\Programs\Python\Python312\Scripts\streamlit.exe run .\streamlit_test.py

    The plot is not showing as stacked barplot, but the bars are next to each other.

    [​IMG]

    I verified that the streamlit and python versions are the same for both cases (streamlit version 1.45.1 and python 3.12.

    Is this a bug in streamlit or am I missing something?

    Continue reading...

Compartilhe esta Página