streamlit / streamlit

Streamlit — A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
35.46k stars 3.08k forks source link

st.expander expanded/collapsed state #2399

Open LeoTafti opened 3 years ago

LeoTafti commented 3 years ago

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.

AngelCarballoCremades commented 3 years ago

Hi!

I'm interested in this issue, any updates so far?

As well as knowing the expanded state, it would be usefull to alter the expanded state too (I want to colapse an expander when something happens).

beep-92 commented 3 years ago

+1

usbader commented 2 years ago

Me too.

jmbf2011 commented 2 years ago

I'm quite interested also in this issue. I would like to avoid API requests which are sent under unexpanded st.expander.

YoungXu06 commented 2 years ago

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

enzedonline commented 2 years ago

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 😉)

RobertoFN commented 2 years ago

+1

quannabe commented 2 years ago

This would be an excellent addition! I load multiple expanders that contain some "heavy" code. The initial UI delay when loading is somewhat annoying but using @st.cache helps.

alebarquin commented 1 year ago

Had anyone try this method:

if 'is_expanded' not in st.session_state:
    st.session_state['is_expanded'] = True
container = st.expander("XXX", expanded=st.session_state['is_expanded'])
with container:
    [DO STUFF]
    st.session_state['is_expanded'] = False

I thought it would be a good idea, but working to me though.

ghost commented 1 year ago

Had anyone try this method:

if 'is_expanded' not in st.session_state:
    st.session_state['is_expanded'] = True
container = st.expander("XXX", expanded=st.session_state['is_expanded'])
with container:
    [DO STUFF]
    st.session_state['is_expanded'] = False

I thought it would be a good idea, but working to me though.

Working only after manual rerun.

kaankork commented 1 year ago

This would be a useful functionality. In my use-case, I have two expanders and each has a radio list in it. I want to be able to say - if one expander is expanded (expander_state = True) then radio_selection would use the selection in this expander.

DontAskFuture commented 1 year ago

Hi,

This is a useful feature. Is there any update on it?

lucasrodes commented 1 year ago

+1

nanshens commented 1 year ago

Hope to add this feature. Every time you change something in the expander, it will shrink automatically!!!

jrieke commented 1 year ago

6848 suggested introducing an on_expand callback.

sfc-gh-smao commented 1 year ago

+1

yuanher commented 1 year ago

+1

peteromallet commented 1 year ago

Hi! Any update on this? Saw it had been moved back on the roadmap :(

breckbaldwin commented 7 months ago

Please implement expander state as described...this is important and impacts relevance of streamlit to broader use.

ohmatheus commented 4 months ago

+1 !!!

kaoulis commented 3 months ago

+1 The same will be useful for tabs as well!

PierreW42 commented 2 months ago

+1

vmalyi commented 3 weeks ago

Hey there, any plans to introduce this?

Thanks!