Clear the text in text_input

It is explained in a comment to an issue linked above

The key points are:

  • You need to assign a key to the text_input.
  • You can change the widget value programatically by assigning a value to that key:
    st.session_state[key] = new_value
  • If you want to change the value in response to an user interaction (like pressing a button), do it in a callback so that the change is effective inmediately.
import streamlit as st

def clear_text():
    st.session_state["text"] = ""

input = st.text_input("text", key="text")    
st.button("clear text input", on_click=clear_text)
st.write(input)