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

Streamlit plots setting incorrect height and width if checkbox unselected #7597

Closed
3 of 4 tasks
andy23432 opened this issue Oct 24, 2023 · 2 comments · Fixed by #8191
Closed
3 of 4 tasks

Streamlit plots setting incorrect height and width if checkbox unselected #7597

andy23432 opened this issue Oct 24, 2023 · 2 comments · Fixed by #8191
Labels
feature:st.plotly_chart priority:P3 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working

Comments

@andy23432
Copy link

andy23432 commented Oct 24, 2023

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

I want to make some plots depending on an option selected in the sidebar. When I have 2 plots and I remove the first one via a checkbox the lower plot take the height and container size of the first one despite not setting those.

Showing both:
image

Showing only the second:
image

In the second image you can see that the figure 2 now has use_container_width=True despite it being set to False in code and it has taken the height setting made on figure 1.

Reproducible Code Example

Open in Streamlit Cloud

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

st.set_page_config(layout="wide", page_title="Demo")


with st.sidebar:
    # option to show or hide figure 1
    show_fig_1 = st.checkbox("show_fig_1", True, key="show_fig_1")

data = {"a": [1, 2, 3], "b": [1, 4, 9]}
df = pd.DataFrame(data)

if show_fig_1:
    st.header("Figure 1")
    fig_1 = px.line(df, x="b", y="a")
    fig_1.update_layout(height=1000)
    st.plotly_chart(fig_1, use_container_width=True)

st.header("Figure 2")
fig_2 = px.line(df, x="a", y="b")
# when show_fig_1 is unselected the height is 1000 and use_container_width becomes True
st.plotly_chart(fig_2, use_container_width=False)

Steps To Reproduce

  1. Run the code above
  2. Click the checkbox

Expected Behavior

I would expect figure 2 to keep the default height and container width to be False when the checkbox is unselected

Current Behavior

No response

Is this a regression?

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

Debug info

  • Streamlit version: streamlit-1.27.2
  • Python version: 3.10
  • Operating System: Windows 10
  • Browser: Chrome

Additional Information

No response

@andy23432 andy23432 added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Oct 24, 2023
@github-actions
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

@andy23432 andy23432 changed the title Streamlit plots setting incorrect height and width if checkbox selected Streamlit plots setting incorrect height and width if checkbox unselected Oct 24, 2023
@andy23432
Copy link
Author

andy23432 commented Oct 24, 2023

I've just noticed that by commenting out st.header("Figure 1") in the code above the issue goes away

@mayagbarnes mayagbarnes added status:confirmed Bug has been confirmed by the Streamlit team priority:P3 feature:st.plotly_chart and removed status:needs-triage Has not been triaged by the Streamlit team labels Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.plotly_chart priority:P3 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants