question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expander resets its expanded state when new elements are included.

See original GitHub issue

Summary

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

  1. 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'])
  1. Open the Expander
  2. 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:open
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
kmcgradycommented, Mar 10, 2022

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.

import streamlit as st

checked = st.checkbox("I have something")
placeholder = st.empty()
if checked:
    placeholder.write("Checked")
with st.expander("expand"):
    a = st.selectbox("Choose 1", ['1','2'])

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!

0reactions
davnatcommented, Sep 2, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found