Greetings!
I have come to an issue where the input box (text, number, etc) does not refresh the current data assigned to it if the input was modified by code and the input was entered twice by the user
The code below can be used to reproduce the issue:
import streamlit as st
x = ""
i = 0
def update():
global x, i
x = st.session_state["input"]
if len(x) > 3:
x = ""
i = i + 1
@st.fragment
def layout():
st.text_input(label="INPUT", key="input", value=x, on_change=update)
st.write(f"times updated [ {i} ]")
st.write(f"input value [ {x} ]")
def main():
layout()
main()
Steps to reproduce:
- Input any 3 or lower chars in the box
- Input a value larger than 3 characters
- (x) gets assigned an (‘‘) value, refreshing the input box
- Input the same value that was input in step 3
- The input box keeps the input value, (x) changes to (‘‘), and the counter (i) increases
Example:
- input qwe # box=”qwe” ; x=”qwe” ; i=1 ;
- input qwer # box=”” ; x=”” ; i=2 ;
- input qwer # box=”qwer” ; x=2”” ; i=3 ;
Is there any approach to deal with this issue?
Please take a moment to search the forum and documentation before posting a new topic.
If you’re creating a debugging post, please include the following info:
- Are you running your app locally or is it deployed? > Local
- If your app is deployed:
a. Is it deployed on Community Cloud or another hosting platform? > N/A
b. Share the link to the public deployed app. > N/A - Share the link to your app’s public GitHub repository (including a requirements file). > N/A
- Share the full text of the error message (not a screenshot). > N/A
- Share the Streamlit and Python versions. > streamlit==1.48.0 ; Python==3.12.10