question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Text input with value sometimes reverts input

See original GitHub issue

Summary

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
ShaharMyndcommented, Feb 9, 2021

@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.

3reactions
nthmostcommented, Feb 14, 2020

Still a problem. I just reproduced this error using the OP code.

Additionally, setting a key on the text_input doesn’t help.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found