Expander resets its expanded state when new elements are included.
See original GitHub issueSummary
A expander resets when there are changes in the DOM (like an element is inserted before it). This is likely because the element is unmounted and mounted triggering a reset to the expander itself
Steps to reproduce
- Run streamlit with the following code:
import streamlit as st
if st.checkbox("I have something"):
st.write("Checked")
with st.beta_expander("expand"):
a = st.selectbox("Choose 1", ['1','2'])
- Open the Expander
- Click on the checkbox
Expected behavior:
The expander should remain open with “Checked” appearing above it.
Actual behavior:
The expander collapses
Is this a regression?
No
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
Expander Class (System.Windows.Controls) | Microsoft Learn
Represents the control that displays a header that has a collapsible window that displays content.
Read more >Status of State Medicaid Expansion Decisions: Interactive Map
This page displays an interactive map of the current status of state decisions on the Affordable Care Act's Medicaid expansion.
Read more >The expansion of chemical space in 1826 and in the 1840s ...
The expansion of chemical space in 1826 and in the 1840s prompted the convergence to the periodic system.
Read more >Find Medicaid coverage in your state - HealthInsurance.org
Georgia had intended to include a work requirement as part of its partial Medicaid expansion, and CMS (under the new Biden administration) ...
Read more >Medicaid expansion to the new adult group - MACPAC
In 2021, the Centers for Medicare & Medicaid Services (CMS) notified many of these states that certain elements of their demonstrations (i.e., work...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @simonlipsonrisk I can try to provide guidance, but would need to look at the code. The main challenge that always exists is connecting the actual line of code to the specific element in the DOM. In many cases, we connect it correctly, but expanders have been unique as a layout feature and not an element.
This is a result of an element appearing or disappearing before causing a misalignment in this connection. For the example above, The following workaround would work.
Note the use of
st.empty()
to signify something is there, but not necessarily used is something that allows you to not have this problematic behavior.Hope that helps!
I think I’m also hit by this, on v1.12.2. I have some expanders with dynamic content inside, and they keep closing whenever something in the content changes: it’s quite annoying. If expanders had a state key I could try to write a workaround, but this is not the case. Do you have any suggestions?