howdy, team!
I want to run Streamlit where text inputs’ content caches to file. This experiences a lag by-one update problem similar to this historical issue. Expanding, the file content lagging oscillating resets the value inducing data concerns.
Minimum reproducible example:
import streamlit as st
with open("tmp", "r+") as f:
value = f.read()
st.write('original value or from file:')
st.write(value)
value = st.text_input('change value:', value)
st.write(value)
with open("tmp", "w+") as f:
f.write(value)
Timeline:
- start file, input text, and value all
0
- update input text
1
> value and file both1
- update input text
2
> value2
but file1
- update input text
3
> value2
and file2
- update input text
3
> value3
but file2
- update input text
3
> value and file both3
Had expected value and file to remain synchronized. Or at least input text to not reset. Also noting if you run R
between editing input text, problem goes away.
Video uploaded here in Youtube. First half of video demonstrates issue. Second half shows difference in browser element focus which appears to relate to oscillating change in functionality which is only speculation on related play in.
I assume the community does this ballpark (although different to my implementation to avoid this issue) but am having trouble knowing what to search to pivot. Kindly share a working example or link previous.
Locally deployed
$ streamlit --version
Streamlit, version 1.37.1
$ python3 --version
Python 3.12.3
$ pip3 --version
pip 24.2 from /opt/homebrew/lib/python3.12/site-packages/pip (python 3.12)