Button inside button

Hello everyone,
I was trying to make sequence process in my app by clicking buttons, and I figure out that when I want to show a result for a button which is inside another button it doesn’t work, cloud anyone explain this issue to me
thanks in advance …

little lines to make it more clear

if st.button('1'):
    st.write('you clicked the first button')
    if st.button('2'):
        st.write('you clicked the second button')

( by clicking button 2 the page seems like refreshing )

Yes! I am also facing this issue. It’s bit frustrating…
If you get the solution, kindly update here. Thank u

1 Like

Hi there.
Here is a solution using SessionState, I hope it helps:

import streamlit as st
import SessionState

button1 = st.empty()
text1 = st.empty()
button2 = st.empty()
text2 = st.empty()

ss = SessionState.get(button1 = False)

if button1.button('1') :
    ss.button1 = True

if ss.button1:
    text1.write('you clicked the first button')
    if button2.button('2'):
        text2.write('you clicked the second button')
1 Like

Hey @medloug (and @Tirumaleshn1),

The reason for this is the button was originally designed to be a one-time click, and only remembers that it’s been clicked for one “run through” of the app.

I actually review this in this shorts video (this part starts at 1:19 in):

Very Soon with the release of Session State, you will be able to change this and have your app remember the previous button click. So keep an eye out for that release!

Happy Streamlit-ing!
Marisa

2 Likes

Thank you so much for your support. Hoping, that we get our expected feature.

Hello, Actually I didn’t find a solution but I overcome the problem by merging and using the different interactive widgets available(checkbox inside a button inside selectobox …)