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
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.