I am trying to implement Streamlit UI with two mutually exclusive operation button. each button has nested buttons. The buttons behavior should be like if i click on one button, than functions related to another button should not be visible, the code, i attached is working , but on clicking second button, which could be any of two, the content from previous button is still on UI. I tried multiple approaches. i solved nested button problem using st.session state. but when i select second button after clicking on first button, content from first button is still there, which i don’t expect . vice versa. please help me to solve this.
Sorry for bad english
sideb=st.sidebar
button1 = sideb.button('Single')
if st.session_state.get('button') != True:
st.session_state['button'] = button1 # Saved the state
if st.session_state['button'] == True:
st.write("button1 is True")
option=st.selectbox('Select App?',
('A', 'B', 'C'),index=0)
st.write('You selected:', option)
option=option.lower()
''''SOME CHATTING APP WITHOUT ANY BUTTON '''
button2 = sideb.button('Multiple Queries')
if st.session_state.get('button2') != True:
st.session_state['button2'] = button2 # Saved the state
if st.session_state['button2'] == True:
uploaded_file = st.file_uploader("Choose a file with app_name and list_of questions.", type=['xlsx'], accept_multiple_files=False)
st.write("button2 is True")
if uploaded_file is not None:
stqdm.pandas()
df=pd.read_excel(uploaded_file)
if st.button('Generate'):
st.write("Do your logic here")
with st.spinner('Wait for it...'):
df['Answers']=df.progress_apply(qs, axis=1)
AgGrid(df)
st.success('Done!')
csv = convert_df(df)
download2 = st.download_button(
label="Download Answers",
data=csv,
file_name='Answers.csv',
key='download-csv'
)