Question about Expander and radio

:rotating_light: Before clicking “Create Topic”, please make sure your post includes the following information (otherwise, the post will be locked). :rotating_light:

  1. Are you running your app locally or is it deployed?
    —> locally
  2. If your app is deployed:
    a. Is it deployed on Community Cloud or another hosting platform?
    b. Share the link to the public deployed app.
  3. Share the link to your app’s public GitHub repository (including a requirements file).
  4. Share the full text of the error message (not a screenshot).
  5. Share the Streamlit and Python versions.
    python == 3.10.12
    streamlit == 1.27.2

hello everyone.
I created code that, when I click a button, creates 20 expanders containing radio buttons.
It ran normally, but
If I select the radio button belonging to any expander,
All 20 expanders created will disappear.
but selectChoice method called successful in my code.
What could be the problem? Below is the code I wrote.

import streamlit as st

def selectChange(index):    
    choice = st.session_state[‘exp%s’%index]
    print(index, choice)

if st.button("Make 20 Expander"):
    for i in range(20):
        exp = st.expander('Custom radio button VS Native radio button %s'%i)
        exp.header('Custom radio button')
        custom_choice = exp.radio(
            label='pick one',
            options=['option 1', 'option 2', 'option 3'],
            index=None,
            key="exp%s"%i,
            on_change=selectChage, arts=(i,)
        )

Hello @Byungchul_Jung, buttons do not save their state, so after you interact with the radio option, the button goes back to False. You can find a better explanation of that behavior here in section 1. Buttons aren’t stateful:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.