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.

st.expander expanded/collapsed state

See original GitHub issue

Problem

I’d like to be able to know whether a st.expander is expanded or collapsed (e.g. to show something on the main layout only when an expander in the sidebar is in expanded state).

Solution

MVP: Something like st.expander().expanded as a bool would be nice.


Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

If you’d like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:8

github_iconTop GitHub Comments

1reaction
enzedonlinecommented, May 17, 2022

Would like to see this. I want to hide charts etc not in use which are quite processor intensive and only run the code when the expander is expanded. Something like:

exp = st.expander("Something Heavy")
with exp:
    if exp.expanded:
        st.write(heavy_function())

At the moment, everything is run, even in the hidden content.

Could also be included as an attribute for the expander:

with st.expander("Something Heavy", run_when_hidden=False):
    st.write(heavy_function())

(Psuedo-code, but you get the idea 😉)

1reaction
YoungXu06commented, Feb 28, 2022

Getting expander state is a must especially when I need to monitor if users visit the content inside, looking forward to seeing an update!

Read more comments on GitHub >

github_iconTop Results From Across the Web

st.expander - Streamlit Docs
Inserts a container into your app that can be used to hold multiple elements and can be expanded or collapsed by the user....
Read more >
How to add an expandable container in Streamlit - ProjectPro
You can add multi-element containers that can be expanded or collapsed in Streamlit. This can be done using "st.expander".
Read more >
Status of State Medicaid Expansion Decisions: Interactive Map
The Affordable Care Act's (ACA) Medicaid expansion expanded Medicaid coverage to nearly all adults with incomes up to 138% of the Federal ...
Read more >
How do you keep Streamlit widgets from getting reset when I ...
It seems to now work for streamlit>=1.8.0 : Parameters' state is now saved. Of course, it also works with the st.expander too.
Read more >
Parking Expansion - State Center Community College District
Between the surface level lots and the garage, there will be 986 stalls. Landscaping is nearly done. The offsite street work on Blackstone...
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