hey all, im using streamlit 1.39.0, and want to chunk of code to be reran, this piece of code is the last part of my app and it purpose is to display a message to the user saying
“Email sent, check your inbox.” but I cant grasp the idea of how to use st.rerun or st.fragment, here is my code if anyone can help that would be appreciated:
data = load_data()
if st.session_state["email"] in data:
progress = data[st.session_state["email"]]
if progress.get("task_complete", False):
st.success("Task completed successfully! You can now submit a new request.")
st.session_state["task_complete"] = False
if progress.get("email_sent", False):
st.success("Email sent, check your inbox.")
Can you explain a little more about what exactly you’re trying to accomplish? You may not need st.rerun or st.fragment, depending on how you want your app to work.
Here’s a simple app with your code included that works as-is, but I’m not sure how closely this matches what you’re trying to accomplish:
import streamlit as st
if "email" not in st.session_state:
st.session_state["email"] = "test@test.com"
def load_data(request_id):
return {"test@test.com": {"task_complete": True, "email_sent": True}}
request_id = st.text_input("Enter request id")
if st.button("Submit request"):
data = load_data(request_id)
if st.session_state["email"] in data:
progress = data[st.session_state["email"]]
if progress.get("task_complete", False):
st.success(
f"Task {request_id} completed successfully! You can now submit a new request."
)
st.session_state["task_complete"] = False
if progress.get("email_sent", False):
st.success("Email sent, check your inbox.")
In this case, as soon as you interact with a different widget (in this case, the text_input), it automatically reruns the app, so the button gets reset and the task complete message goes away.
You might also consider using st.toast - Streamlit Docs, which is great for displaying temporary messages like this