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: