Hi to all,
I wish to try the enabling of buttons in “cascade manner”, but I found some issues.
I wrote the issues as comment, inside the code (row 36 and row 39).
Some one can exaplain to me where is my fault?
The principals issue are the 3° button feel the change status, but the st.session_state don’t sing it.
Te last thing that the code must to do is change the text a row 32, but this doesn’t happen, why?
Thanks.
Stefano G.
import streamlit as st
import time
def change_button_status(button_name: str):
# st.write(f"{button_name} - {st.session_state[button_name]}")
st.session_state[button_name] = not st.session_state[button_name]
def sign_end():
st.session_state["output"] = "Finito!"
st.set_page_config(page_title="Enable Buttons", layout="wide")
if "output" not in st.session_state:
st.session_state["output"] = "Lancio operazione ....."
if "Button2" not in st.session_state:
st.session_state["Button2"] = False
if "Button3" not in st.session_state:
st.session_state["Button3"] = False
if st.button("Button1", disabled=False):
change_button_status("Button2")
if st.button("Button2", disabled=not st.session_state["Button2"]):
change_button_status("Button3")
if st.button("Button3", disabled=not st.session_state["Button3"]):
st.text(st.session_state["output"])
with st.spinner('Attendi completamento...'):
time.sleep(5)
st.success('Done!')
# this call don't change the value of the st.text at row 32, why?
sign_end()
# I must add if, else the status don't change
if st.session_state["Button3"]:
st.session_state["Button3"] = False
# Print the session state to make it easier to see what's happening
st.write(st.session_state)
Hi @ferdy,
I wish to have a description about the process that is running and at the end of process this description must change.
Under there is my code, how can I achieve this goal?
Thanks
import streamlit as st
import time
def change_button_status(button_name: str):
# st.write(f"{button_name} - {st.session_state[button_name]}")
st.session_state[button_name] = not st.session_state[button_name]
output = '''In this moment the _service_ processing
....
....'''
st.set_page_config(page_title="Enable Buttons", layout="wide")
if "output" not in st.session_state:
st.session_state["output"] = output
if "Button2" not in st.session_state:
st.session_state["Button2"] = False
if "Button3" not in st.session_state:
st.session_state["Button3"] = False
def sign_end():
st.session_state["output"] = "Completed!"
if st.button("Button1", disabled=False):
change_button_status("Button2")
if st.button("Button2", disabled=not st.session_state["Button2"]):
change_button_status("Button3")
if st.button("Button3", disabled=not st.session_state["Button3"]):
st.markdown(st.session_state["output"])
with st.spinner('Wait please .....'):
time.sleep(5)
# this call don't change the value of the st.text at row 32, why?
sign_end()
st.success('Done!')
# I must add if, else the status don't change
if st.session_state["Button3"]:
st.session_state["Button3"] = False
# Print the session state to make it easier to see what's happening
st.write(st.session_state)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.