Thanks @CarlosSerrano, I have already tried the value attribute, it only works on page load. That is not what I want.
What I want for example, is as follows:
Present a page with 3 empty input fields, URL, Title, Text.
If the user provides the url and presses the “Fetch” button, my program fetches the document and I want to update the title and the text. This is what I cannot do now.
Let the user summarize the title and the text if he wants.
If the user, press the “Save” button, I save whatever is there in the url, title and text inputs.
title = st.text_input(“Title:”, key=“titleInput”, value=“Page title will come here!”)
page = fetchPage(url)
title = page[“title”]
How can I do instruct Streamlit to update the title field with the new of the variable title?
If you have session keys for those values, you can assign them in a function and use it on a callback. That will allow you to add the behavior you want using the value attributes and session state.
Hi @Configentia , If I understand correctly, you wanted to store the given input and update in the response variable and also update in the session.
For that you can try the below code.
response = {
"method": "retrieve",
"title": "China’s Factory Activity Sparks Hope Slump Is Bottoming Out",
"date": "2023-08-31",
"source": "Bloomberg",
"status": "Success"
}
title = st.text_input("Title:", key="titleInput")
date = st.text_input("Date:", key="dateInput")
source = st.text_input("Source:", key="sourceInput")
response["title"] = title
response["date"] = date
response["source"] = source
st.session_state['titleInput'] = title
st.session_state['dateInput'] = date
st.session_state['sourceInput'] = source
If I’m wrong at getting you question please help to understand it in better way.