Create a new text_input every time I click the button


How can I create new text boxes (text_input) by clicking a button. As shown in the reference image, a new text box should get created every time I click the button (something like click to add new row functionality)

Hi, I just made it come true:

here is the code:

import streamlit as st
import random
import string

if 'count' not in st.session_state:
	st.session_state.count = 0

def add_new_row():
	st.text_input("Please input something",key=random.choice(string.ascii_uppercase)+str(random.randint(0,999999)))

if st.button("Add new row"):
	st.session_state.count += 1
	if st.session_state.count>1:
		for i in range(st.session_state.count-1):

the most import thing is how to generate different key for the newest text_input
I used the


to ensue an unique key will be genreated when button be clicked every time.

How can I save state of each input in the above scenario?

1 Like