How to delete text input content and transfer the value / state to the next rerun?

Hello,
I am working on a porting a simple math app from Tkinter to a web app
and would like to use Streamlit for that.
But I can’t figure out how to get it right.

Originally the text input box is empty.
Then the user inputs a value and clicks Check.
In the next run the text input box should be empty and the number is used
somewhere. Same thing on every Check.

This is what I got so far:

import streamlit as st

if 'id_answer' not in st.session_state:
    st.session_state['id_answer'] = ''

value = st.session_state['id_answer']

placeholder_text_box_answer = st.empty()
check = st.button('Check', 'id_check')
placeholder_text_box_feedback = st.empty()

if check:

    value = ''

    st.session_state['id_answer'] = ''

placeholder_text_box_feedback.text(f'value was {value}')

answer = placeholder_text_box_answer.text_input(f'',
                                                value=st.session_state['id_answer'], 
                                                max_chars=10,
                                                key='id_answer')

Any ideas how to solve that?

This seems to be a bug and is currently discussed and worked on.
The values set in st.session_state do not propagate to the frontend.

Issue did not exist in Streamlit 0.87.0

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.