Hi! I’m creating an application in which the user will upload some csv files and will press a button to run an optimization that is computationally expensive. While the execution takes place I’d like to disable the run button and also all the buttons of the sidebar menu. I could manage to disable the run button but the same mechanism doesn’t seems not to apply to the sidebar menu buttons. Anybody has an idea of what’s to be done?
the piece of code for the button is:
if 'run_button' in st.session_state and st.session_state.run_button == True:
st.session_state.running = True
else:
st.session_state.running = False
if st.button('Compute', disabled=st.session_state.running, key='run_button'):
#if st.button('Compute'):
# Introduce a 5-second delay
st.write("Processing, please wait...")
with st.spinner('Wait for it...'):
time.sleep(3) # 5-second delay
# Proceed with backend communication
with st.status("Working..."):
st.write("Storing your petition..")
result_store = store_dataframe(df1, backend_store) # Using the first file for storage
if result_store:
st.write("Store - Received result from FastAPI:")
# st.write(result_store)
st.write("Computing")
result_compute = compute_dataframe(df1, backend_compute) # Using the first file for computation
if result_compute:
st.write("Compute - Received result from FastAPI:")
# st.write(result_compute)
st.write("Compute - Finished!")
st.session_state.running = False
#st.session_state.run_button = False # can't run but in practise the state is set to false after making click into the following button
if st.button('Clean'):
st.write("Cleaned!")
and the piece of the code for the sidebar menu buttons is:
if 'running' not in st.session_state:
st.session_state.running = False
if st.sidebar.button("Main Page", disabled=st.session_state.running):
st.session_state.page = "Main"
if st.sidebar.button("Restrictions", disabled=st.session_state.running):
st.session_state.page = "Restrictions"
# Main page content
if st.session_state.page == "Main":
st.markdown('<h1 class="centered-title">Smart Engine</h1>', unsafe_allow_html=True)
thanks in advance