Hi, I’m trying to make a program that will show different elements for different steps but for some reason during the “loop_function” step the text from the previous step (“process_steps”) is still visible but greyed out.
import streamlit as st
import time
# Step 1: File upload
st.title("File Processing App")
if "step" not in st.session_state:
st.session_state.step = "waiting_for_file"
st.session_state.data = [] # Placeholder for loop data
st.session_state.checkboxes = [] # Store checkbox states
# Waiting for the file
if st.session_state.step == "waiting_for_file":
uploaded_file = st.file_uploader("Upload your file", type=["txt", "csv"])
if uploaded_file:
st.session_state.step = "confirm_file"
st.session_state.uploaded_file = uploaded_file
# Confirming file upload
if st.session_state.step == "confirm_file":
st.write("File uploaded successfully.")
if st.button("Start Processing"):
st.session_state.step = "process_steps"
st.rerun()
# Step 2: Processing steps
if st.session_state.step == "process_steps":
st.write("Processing steps...")
processing_steps = ["Step 1: Preprocessing", "Step 2: Analysis", "Step 3: Preparation"]
for step in processing_steps:
st.write(step)
time.sleep(1) # Mock processing time
st.session_state.step = "loop_function"
st.rerun()
# Step 3: Loop function
if st.session_state.step == "loop_function":
st.write("Executing loop...")
items = ["Item 1", "Item 2", "Item 3", "Item 4"] # Mock data
# Simulate processing each item
for item in items:
st.session_state.data.append(item)
time.sleep(1) # Mock processing time
st.session_state.step = "display_checkboxes"
st.rerun()
# Step 4: Display checkboxes
if st.session_state.step == "display_checkboxes":
st.write("Review items:")
for idx, item in enumerate(st.session_state.data):
if len(st.session_state.checkboxes) <= idx:
st.session_state.checkboxes.append(False)
st.session_state.checkboxes[idx] = st.checkbox(item, value=st.session_state.checkboxes[idx])
if st.button("Confirm Selection"):
st.session_state.checked_count = sum(st.session_state.checkboxes)
st.session_state.step = "summary"
st.rerun()
# Step 5: Summary and next steps
if st.session_state.step == "summary":
st.write(f"Number of selected items: {st.session_state.checked_count}")
if st.button("Continue to Final Steps"):
st.session_state.step = "final_steps"
st.rerun()
if st.session_state.step == "final_steps":
st.write("Executing final steps...")
time.sleep(1)
st.write("Processing complete!")
I’m also using st.rerun() to remove previous elements immediately. It works for other elements, is it the right way to do it? How do I properly hide/disable text or elements from the previous step?