import streamlit as st
st.title("Example of when default to set to None")
st.write("When the default of a text_input (and some other input widgets) is set to None this is sticky i.e. doesn't change even if the default is updated.")
st.write("This occurs when a key is specified which is sometimes a necessity e.g. when creating input fields using a for loop.")
selected_default = st.radio("Select the default value", ["Yes", "No", "Long string; Long string; Long string; Long string; Long string", None])
input = st.text_input("Input field", key = "test", value = selected_default)
st.write("Use the radio input to dynamically set the default value for the text input field. It is possible to change between the string values but once None is selected it cannot be overwritten.")
Above is a mini example of the issue that I encountered when building an app. In my app I have worked around the issue but wonder if this is the intended behaviour of the default value for the text input widget.
In summary:
When the default of a text_input (and some other input widgets) is set to None, this is sticky i.e. doesn’t change even if the default is updated. This occurs when a key is specified which is sometimes a necessity e.g. when creating input fields using a for loop. Steps to illustrate: Use the radio input to dynamically set the default value for the text input field. It is possible to change between the string values but once None is selected it cannot be overwritten.
Thanks for any insights
Streamlit and Python versions:
- Python 3.11.9
- streamlit 1.41.1
This example and my main app have only been run locally