Multiple number inputs using same number_input

Hello, I’m working on an application that allows the user to insert multiple school grades (german system, numbers 00-15) using the same number_input, I then want to re-calculate the every time the user adds another grade. I also want the use to be able to easily add and remove these grades. I’ve done some research in the forums here and came accross a similar application that uses text inputs and tasks but the code doesn’t work properly for me andI have no idea how I could adopt the solution for my use case. link to the mentioned conversation

Is this possible to do with streamlit and if yes, how could I implement such a system ?

If this is not the giht place for this sort of question, please let me know.

I answered this on Discord but am still adding the solution here so that other people struggling with the same question may refer to this later.

import streamlit as st

@st.cache(allow_output_mutation=True)
def Nums():
    return []

nums = Nums()
num = st.sidebar.number_input("Input Number")
if st.sidebar.button("Add number"):
    nums.append(num)

try:
    inputs = nums
    st.table(inputs)
    st.write("Sum: ", sum(inputs))
except:
    st.title("Enter some numbers")
1 Like

Thanks for helping me out !
Solution is great and also works in multipage apps in case you are wondering.

1 Like

Awesome. Glad I could help :smile:.

1 Like