The dynamically created text_input boxes disappears when the values are changed


The dynamically created text_input boxes disappears when the values are changed

Steps to reproduce

Code snippet:

import streamlit as st

def gen_res():
    if st.session_state["req_txt"] == "":
        container_form_inp.warning('The text field is empty', icon="โš ๏ธ")
        container_form_inp.success('The text is valid', icon="โ„น๏ธ")
        query, responses = ["A", "B", "C"], [1,2,3]
        for i, (q,r) in enumerate(zip(query, responses)):
            container_form_res_col1.text_input("The "+str(i+1)+" Test Query", key = "Query_"+str(i+1), value = q ,on_change=None )
            container_form_res_col3.text_input("The " + str(i+1) + " Test Results", key="Results_" + str(i+1), value=r, on_change=None)


st.sidebar.success("Select One of the current available features")

container_form = st.form("Form_Input")
container_form.markdown(" **:red[Enter the requirement]**:")

container_form_inp = container_form.container()
container_form_inp_col1, container_form_inp_col2, container_form_inp_col3= container_form_inp.columns([5,1,5])
req_txt = container_form_inp_col1.text_area("Kindly enter the text of the requirement", key = "req_txt")

container_form_inp_col2.markdown("<h1 style='text-align: center; color: grey;'> </h1>", unsafe_allow_html=True)
container_form_inp_col2.markdown("<h4 style='text-align: center; color: grey;'>Or</h4>", unsafe_allow_html=True)

upl_file = container_form_inp_col3.file_uploader("Upload a excel file in proper format")

cmd_gen = container_form.form_submit_button("Generate Test Cases", on_click=gen_res)

container_form_res = st.container()
container_form_res_col1, container_form_res_col2, container_form_res_col3= container_form_res.columns([7,1,7])

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

Explain what you expect to happen when you run the code above.

Actual behavior:

The new created text boxes should not get removed

Debug info

  • Streamlit version: (get it with $ streamlit version)
  • Python version: (get it with $ python --version)
  • Using Conda? PipEnv? PyEnv? Pex?
  • OS version:
  • Browser version:

Requirements file

Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.


  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.

A callback function is something that runs as a prefix to the page load, but only once (per trigger event). In your case, the gen_res function prefixes the page when you click the form submit button. However, that doesnโ€™t make it persist. As soon as anything other interaction triggers a page reload, it goes away. Anything rendered as part of a callback will be transient. In general, donโ€™t put widgets inside callbacks.

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