'Plotly barplot not rendering fine in streamlit app

When rendering a plotly barplot with fig.show(), I get the plot exactly the way I developed it. But when I render it using streamlit's st.plotly_chart(), it gets with another appearance (without the bar labels).

This is how it should be (the plot I get when using fig.show()):

enter image description here

How it renders with st.plotly_chart() (dark theme):

enter image description here

And in light theme:

enter image description here

My code:

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

df = pd.read_excel('file.xlsx', sheet_name='Current_Base')
fig = px.histogram(df,
                   x='number',
                   text_auto=True
                   )
fig.show()
st.plotly_chart(fig)

My relevant settings:

- os: macOS Monterey 12.1
- libs:
   streamlit 1.3.1
   plotly 5.5.0

Could anyone help me with this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source