Text input with value sometimes reverts input
See original GitHub issueSummary
When using an st.text_input
and setting the value=
argument, sometimes the user input is reset to the previous input.
Steps to reproduce
Run this streamlit script that reads a string from a file, sets it as value of a text input, and saves the returned value of the input to the file again:
import streamlit as st
try:
with open('value.txt', 'r') as file:
before = file.read()
except OSError:
before = 'a'
after = st.text_input('Input:', value=before)
st.write('Before:', before, 'After:', after)
with open('value.txt', 'w') as file:
file.write(after)
Expected behavior:
a
+ Enter
= Before: a After: a Input: a
b
+ Enter
= Before: a After: b Input: b
c
+ Enter
= Before: b After: c Input: c
Actual behavior:
a
+ Enter
= Before: a After: a Input: a
b
+ Enter
= Before: a After: b Input: b
c
+ Enter
= Before: b After: b Input: b <<< RESET
This happens on every second input, whenever before
and after
values are not the same.
It works as expected if you use the input without a value:
after = st.text_input('Input:')
Debug info
- Streamlit version: 0.50.2
- Python version: 3.7.4
Might be related to https://github.com/streamlit/streamlit/issues/218
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Input value resets when input is cleared - Stack Overflow
Input value resets when input is cleared ... However, it's not working as expected, if a user tries to delete the existing name...
Read more ><input type="reset"> - HTML: HyperText Markup Language
An <input type="reset"> element's value attribute contains a string that is used as the button's label. Buttons such as reset don't have a...
Read more >How to revert back to a default input field value?
The idea I currently have is to show an icon at the end of the input field in case the default value has...
Read more >Understanding Success Criterion 3.2.2: On Input
So checking a checkbox, entering text into a text field, or changing the selected ... This Success Criterion covers changes in context due...
Read more >Solve Flake In Cypress Typing Into An Input Element
Imagine an application that resets the input field on start up. ... <input type="text" id="flaky-input" value="" disabled /> <script>
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nthmost as said, this is still a problem.
I face the same issue, after creating text_input with a unique key, Sometimes, Usually on the second update The result from the input is the previous value.
Still a problem. I just reproduced this error using the OP code.
Additionally, setting a key on the text_input doesn’t help.