st.toast
Display a short message, known as a notification "toast".
The toast appears in the app's top-right corner and disappears after four seconds.
Warning
st.toast is not compatible with Streamlit's caching and cannot be called within a cached function.
| Function signature[source] | |
|---|---|
st.toast(body, *, icon=None, duration="short") | |
| Parameters | |
body (str) | The string to display as GitHub-flavored Markdown. Syntax information can be found at: https://github.github.com/gfm. See the body parameter of st.markdown for additional, supported Markdown directives. |
icon (str, None) | An optional emoji or icon to display next to the alert. If icon is None (default), no icon is displayed. If icon is a string, the following options are valid:
|
duration ("short", "long", "infinite", or int) | The time to display the toast message. This can be one of the following:
|
Examples
Example 1: Show a toast message
import streamlit as st
st.toast("Your edited image was saved!", icon="π")
Example 2: Show multiple toasts
When multiple toasts are generated, they will stack. Hovering over a toast will stop it from disappearing. When hovering ends, the toast will disappear after time specified in duration.
import time
import streamlit as st
if st.button("Three cheers"):
st.toast("Hip!")
time.sleep(0.5)
st.toast("Hip!")
time.sleep(0.5)
st.toast("Hooray!", icon="π")
Example 3: Update a toast message
Toast messages can also be updated. Assign st.toast(my_message) to a variable and use the .toast() method to update it. If a toast has already disappeared or been dismissed, the update will not be seen.
import time
import streamlit as st
def cook_breakfast():
msg = st.toast("Gathering ingredients...")
time.sleep(1)
msg.toast("Cooking...")
time.sleep(1)
msg.toast("Ready!", icon="π₯")
if st.button("Cook breakfast"):
cook_breakfast()
Tip
Want a new st.toast feature or found a bug? Browse open issues and react with a π on the initial post of the ones that matter to you. Your votes help us prioritize what to work on next.
Still have questions?
Our forums are full of helpful information and Streamlit experts.