Best approach to many inputs

I have a project, where i need around 40 input fields, with default values, on the same page.

Do anybody have any good idea on how to approach this ?

Currently i have created a lot of column, but using st.text_input gives me the following error ( DuplicateWidgetID), when i have multiple with the same default value.

Any ideas is appreciated.

Thanks

/Robert

Hey @rhjensen79!

No worries I can solve the DuplicateWidgetID error for you! :sunglasses:

So that comes up when you have multiple widgets that are identical! for example:

import streamlit as st 

text = st.text_input("Type here")

text2 = st.text_input("Type here") # <-- this throws the error

Thats because widgets are assigned an internal key based on its structure. So identically structured widgets end up with the same internal key.

The way around this is by using the key parameter. This adds a unique string to the end of the generated key, so that Streamlit knows which input is from which widget! I usually add something that makes sense to me and how the widgets are actually used differently. So in this silly example:

text = st.text_input("Type here")

text2 = st.text_input("Type here", key = "last_name")

Happy Streamlit-ing!
Marisa

What kind of input? Is it a form with many text fields or more like a matrix, with numbers only input?

Thanks @Marisa_Smith that sounds like an easy en perfect solution. I will try that later.

Regarding the inputs. They are all single line numbers. And they are probably no more than 7-8 digits.

Thanks

Just to give an idea.
This is what it looks like now, and i only have around 50% of the inputs so far.
It looks like it will end up as a mess.

do you think something like this would work for you?

https://share.streamlit.io/pablocfonseca/streamlit-aggrid/main/examples/many_inputs.py

Its based on Streamlit-aggrid component. GitHub - PablocFonseca/streamlit-aggrid

1 Like

Hey @rhjensen79

I noticed that the first colum down the sides of “type” all has preloaded options.

What about using a st.selectbox for those, and that way you wont need a matrix of all those columns.

I will see if I can mock up what I am thinking later, just on my phone atm.

If that’s not a possibility i think @PablocFonseca has a good option for you!

Happy Streamlit-ing!
Marisa

1 Like

I think i know exactly what you are thinking. That is a really good idea, and would also allow me to select which rows i need, and not like today, where they are all shown.

I need to wrap my head around how to do it, but that would make my code so much easier, if i’m right.

1 Like

Did not see your response until now.

That is perfect. Thanks.
I’m guessing i can reference every cell, and do calculations on them.

Thanks.

@PablocFonseca that’s a really great tool !!! well done !!! :clap:

1 Like

A post was split to a new topic: Multiple text inputs

Hi Pabloc,

Please can you make the file public:
[https://share.streamlit.io/pablocfonseca/streamlit-aggrid/main/examples/many_inputs.py]

Thanks so much!
Peter

currently working solution can be done by pandas dataframe +

check this out from example : https://editable-dataframes.streamlit.app/

You could take multiple inputs using st.form widget as well