Beta_expander in sidebar requires other widgets not to have st.sidebar

The beta_expander looks fantastic in the sidebar. One strange thing is that if widgets inside the expander block have st.sidebar.<widget_type>, it shows them outside the expander. If the widgets have st.<widget_type> it will show them within the expander on the sidebar.

THE RADIO BELOW WILL APPEAR ON THE SIDEBAR INSIDE THE EXPANDER:
with st.sidebar.beta_expander(‘Preferences’):
st.radio(“Select language”, [“English”, “Hindi”])

THE RADIO BELOW WILL APPEAR ON THE SIDEBAR OUTSIDE THE EXPANDER:
with st.sidebar.beta_expander(‘Preferences’):
st.sidebar.radio(“Select language”, [“English”, “Hindi”])

5 Likes

I am also facing similar issue. did you get a solution?

This is still happening… I just ran into it.
It is confusing as it does not follow their standard naming format

FYI - Bug raised and accepted - Sidebar Expander - The widgets do not use the Sidebar method to be nested inside of it · Issue #3157 · streamlit/streamlit (github.com)

Yogesh, it works well if you don’t use st.sidebar inside the expandar loop. For example:

with st.sidebar.beta_expander("test'):
    st.info("This will work")

In the example above, the info widget will appear inside the expander. It’s not intuitive but it works.