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