my_area = st.text_area(":blue[My text here :]",height=2000)
new_text = My_function(my_area)
my_area = st.text_area(":blue[My text here :]",new_text,height=2000)
I’m not entirely clear on the flow you want, but one way to accomplish this is to set the default value of your textbox to be based on a value in st.session_state, and then update that value in the session state and rerun the app
import streamlit as st
if "default" not in st.session_state:
st.session_state["default"] = "Default text" * 100
my_area = st.text_area(
":blue[My text here :]", value=st.session_state["default"], height=2000
)
if st.button("Update default example"):
st.session_state["default"] = "Updated text" * 100
st.experimental_rerun()
For OP’s use case, the solution is to use a callback function which can be invoked on a button click. This is because a button click re-runs the entire script again, so that on the re-run, the modified text is rendered in the text area. So in addition to @Goyo’s solution here, the following also works:
import streamlit as st
st.session_state.text = st.session_state.get("text", "").upper()
st.text_area("Enter text", key="text")
st.button("Upper Text")