How do you get Plotly to adjust plot size based on screen resolution in a Streamlit app?
Asked Answered
P

2

10

I'm building a streamlit app with plotly graphs. However, I'm finding it hard to set a dynamic plot width in the plotly figures (I expect the app to be viewed in multiple resolutions).

Is there a way to tell plotly to use 100% (or 80%, etc.) of the width (whatever number of pixels that might be).

Profluent answered 28/10, 2021 at 9:9 Comment(0)
P
19

You can use the use_container_width argument of st.plotly_chart:

st.plotly_chart(fig, use_container_width=True)
Profluent answered 28/10, 2021 at 9:16 Comment(4)
st.plotly_chart(fig, use_container_width=True) isn't working for meJunia
Happy to help, but can you share more context?Profluent
Adding the setting as recommended had no effect on my figure widths. I'm using plotly figuresJunia
is there any hack to automatically adjust the height ?Bertrand
A
3
fig.update_layout(height=800)

st.plotly_chart(fig,use_container_width=True,height=800)

I used this and it worked fine. I had to use both only then it worked.

Androcles answered 28/11, 2022 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.