I’m trying to use a st.empty() placeholder at the bottom of my page, which I write to via callback. Unfortunately, anything I write to the st.empty() is immediately overwritten next app cycle. I was hoping to “reserve” a place at the bottom of the page, then write output there after doing some processing.
I’m surprised this doesn’t throw an error, actually. The callback executes before the script (namely before your empty container is defined). In any case, your script always ends with output_placeholder = st.empty() so that 's always the last thing to execute.
Try storing your output in Session State then simply displaying it at the end.
import streamlit as st
def process_user_input():
user_input = st.session_state["user_input"]
output = f"Output from input: {user_input}"
st.session_state["output"] = output
st.text_area(label="User Input", placeholder="Enter stuff here", key="user_input", on_change=process_user_input)
if "output" in st.session_state:
st.write(st.session_state["output"])
If you only want to display your result briefly and then have it go away. You can delete the key from session state after displaying it:
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.