Refresh Caching with text-input vs write (experimental_allow_widget bug?)


I have an example code below. I noticed that st.text_input for caching either doesn’t work properly or I am doing something incorrectly. Below I have an example of a function (printer) returning a hard coded string message, which is successfully cached and reappears after a refresh. While the 2nd function (printer2) saves the user input in the cache temporarily but it does not show the text input on the st.write after browser refresh like the first function (printer1) despite being very similar functions. The goal is that I want the user input to also be saved in the cache and displayed after refresh for my own personal app.

Steps to reproduce

Code snippet:

import streamlit as st
import time

def printer():
    return 'Message'

st.write(printer()) #after a refresh "Message" shows up successfully and cached

def printer2():
    p =  st.text_input(label='com')
    return p

st.write(printer2()) #after a refresh, user text does not show up

Expected behavior:

Both functions should cache the strings and are shown after a browser refresh

Actual behavior:

Only the first function (printer), shows the string after a refresh, while the 2nd function (printer2) does not. Printer2 seems to cache the string initially but after refresh it disappears.

Debug info

  • Streamlit version: 1.24.0
  • Python version: 3.10
  • Using Conda? Yes. Anaconda Spyder
  • OS version: MacOS Monterey 12.6.7
  • Browser version: Mozilla 118.0.1 (64-bit)

Pre refresh

Post refresh
notice the string “Message” still shows up but the user input “words” does not