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

Default plotly chart from the docs overflows st.container with border in standard layout #8244

Closed
3 of 4 tasks
Asaurus1 opened this issue Mar 6, 2024 · 4 comments · Fixed by #8191
Closed
3 of 4 tasks
Labels
feature:st.container feature:st.plotly_chart priority:P3 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working

Comments

@Asaurus1
Copy link
Contributor

Asaurus1 commented Mar 6, 2024

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

See the attached screenshot, which has the code to reproduce shown as well. This is using the example plotly code from the streamlit docs, so I don't think there's anything specific about the data that is being used.

Not sure if this is a "bug" but I would think by default we'd want plotly plots to have the width of their container.

Reproducible Code Example

image_2024_03_06T02_15_02_458Z-1

Import plotly.express as px
Import streamlit as st

With st.container(border=true), st.echo():
    Df=px.data.iris()
    Fig=px.scatter(Df, x="sepal_width", y="sepal_length", color="species")
    st.plotly_chart(Fig)

Steps To Reproduce

  1. Render plot via the code above
  2. See overflow

Expected Behavior

No overflow

Current Behavior

Plot overflows it's container

Is this a regression?

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

Debug info

  • Streamlit version: 1.31.1
  • Python version: 3.11
  • plotly version: will post when off mobile
  • Operating System: Windows
  • Browser: Opera version 4.188

Additional Information

No response

@Asaurus1 Asaurus1 added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Mar 6, 2024
Copy link

github-actions bot commented Mar 6, 2024

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

@mayagbarnes mayagbarnes added status:confirmed Bug has been confirmed by the Streamlit team priority:P3 feature:st.plotly_chart feature:st.container and removed status:needs-triage Has not been triaged by the Streamlit team labels Mar 6, 2024
@mayagbarnes
Copy link
Collaborator

Hi @Asaurus1, thanks for your submission! We would definitely like to have the plotly chart fit properly by default so marking this as a confirmed bug - good news is this can be fixed in your use case by adding use_container_width=True to the chart call as follows:

with st.container(border=True), st.echo():
    Df=px.data.iris()
    Fig=px.scatter(Df, x="sepal_width", y="sepal_length", color="species")
    st.plotly_chart(Fig, use_container_width=True)

@Asaurus1
Copy link
Contributor Author

Asaurus1 commented Mar 6, 2024

@mayagbarnes yeah that makes a lot of sense.

@Asaurus1
Copy link
Contributor Author

Asaurus1 commented Mar 6, 2024

@mayagbarnes if you want it fix this by updating the default width for plotly charts I can probably submit a fix PR. If you think it'll require fancier handling I'll need a bit more description of the intent.

willhuang1997 added a commit that referenced this issue Apr 29, 2024
## Describe your changes

Adds selection support to `st.plotly_chart` that can be used via:

```python
selections = st.plotly_chart(fig, on_select="rerun", selection_mode=("box", "points"))
```

## GitHub Issue Link (if applicable)

- Related: #455
- Closes #5902
- Closes #8244
- Closes #8169
- Closes #7597
- Closes #6324
- Closes #8575
- Closes #8576

## Testing Plan

- Implemented e2e and unit tests.

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.

---------

Co-authored-by: Lukas Masuch <Lukas.Masuch@gmail.com>
Co-authored-by: William Wei Huang <william.huang@snowflake.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.container 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