I want to take multiple inputs in a for loop

for i in range(len(labels):
** st.write(labels[i])**
** final=st.text_input(“final”,key=0)**
** title=st.text_input(“title”,key=1)**
** emotion=st.text_input(“title”,key=2)**
** labels.append(final,title,emotions)**

So the code is just executing the for loop and not waiting for the user to input the value. I want that the next text bar executes when user has entered the value of the previous one.

Also I want to stop the script from rerunning from the top and once some changes are done it executes from that point.


Running all the way through is core to the way streamlit runs.

You might be able to achieve this by giving the inputs unique keys and adding a break in the loop if they aren’t all added but I’d suggest looking at how streamlit processes (from the top each time) and see if you can design a UI that fits that process more closely.

All you need is to use a dictionary. Below is my little workaround.

import streamlit as st

name_dict = {"Anord":"", "Bernald":""}

for k, v in name_dict.items():
    name_dict[k] = st.text_input(k, v)

You can change the values of a dict item to a list or something else.

I am taking input in a for loop.
But for each iteration it is printing a new input box.
I want take input repeatedly in the same input box.

It is filling the page with so many boxes according to the loop count
for i in range(100):
** a=st.text_box(“val”)**
** l.append(a)**

Here my code generates 100 boxes. But I need only one

@xzrokeman please help for this

I’d recommend taking a step back and thinking about how streamlit works (running the script from top to bottom) and how you might design an interface for your problem that fits it. Streamlit (and all libraries) will not neatly make all UIs.

Since your script is running through completely but you only want one input box, I think you need to store the data somewhere else. There’s some hacks for storing inside streamlit but it’s not officially supported. Instead you could store the data in a database, although you’d need to think carefully about the flow.

1 Like

Hey, as @Ian_Calvert said, you’d better reconsider your user interface depending on your use case.
BTW, st.button object is really tricky, maybe there is a solution using SessionState.