not necessarily a question rather a workaround I found for using Plotly charts in Streamlit apps.
When I use Plotly without any sizing guidance, legend usually covers the chart and it is oddly distorted.
Moreover, it often overlaps with the st.subheader() and other elements below it.
My workaround was to set the size of the chart twice:
once in the Plotly object (eg, fig.update_layout(width=1100,height=900) ) - this one actually changes the size of the plot, so it’s readable
and then in the Streamlit command (eg, `st.plotly_chart(fig,width=1100,height=900) ) - this one moves all the subsequent elements below the Plotly chart (no more overlapping!)
I’ve tried using only the Streamlit command, but it wasn’t actually changing the Plotly figure size.
I didn’t even realize that was an option, just thought the size of my plotly charts was off…here is an example – with this code (I can provide more if needed)
Providing a full example would be helpful, as it’s not clear to me what your question is. Are you expecting both charts to be the same size, persisting the height across calls?
Hi @randyzwitch,
Yes, in my example, I’m expecting both charts to be the same size.
And now that I rechecked this, they both are the same size when I run locally, but when I deploy to heroku, the second chart (st.plotly_chart(fig)) gets resized back down…so it may be a separate issue.