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 )
1 Like
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
3 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 …)
Try this, that could be your solution:
import streamlit as st
button1 = st.button('Check 1')
if st.session_state.get('button') != True:
st.session_state['button'] = button1
if st.session_state['button'] == True:
st.write("button1 is True")
if st.button('Check 2'):
st.write("Hello, it's working")
st.session_state['button'] = False
st.checkbox('Reload')
3 Likes
How would look the solution with three nested buttons?
With multiple checkboxes/buttons I used @gabrielfbueno example but not setting st.session_state[‘button’] to False. Seems to work for now.
I solved this for multiple nested buttons by executing the steps in this link:
streamlit sessionstate
Here’s one way to accomplish the 3 nested buttons 3+ Nested Buttons - #2 by blackary