I have the following code, intend to store and display some things according to user inputs on a form.
The problem I’m facing is that I can’t save what the user chooses/types every time he submits the form, the code below only rewrites the previous submit, instead of update it.
Also, I’m not able to store the data after a rerun.
I know I’ll probably have to use st.session_state
somewhere, but I don’t know how or where to implement it.
I’d be really thankful if someone could help me ;).
import pandas as pd
import streamlit as st
# data
items = ['item1', 'item2','item3']
processos = ['processo1','processo2','processo3']
artigos ['artigo_x','artigo_y','artigo_z']
cliente = []
quantidade = []
vol = []
ped = []
# appending data
@st.cache_resource
def action(c,q,v,p):
cliente.append(c)
quantidade.append(q)
vol.append(v)
ped.append(p)
# panel title
st.title('Schedule - V Laundry :spiral_calendar_pad:')
# order register
with st.sidebar.form(key='cad_form', clear_on_submit=True):
st.write("Cadastro de pedidos")
client = st.text_input('Cliente', key='cli')
its = st.selectbox("Selecione o item",pd.Series(items),key='it')
article = st.selectbox("Selecione o artigo", pd.Series(artigos),key='art')
processes = st.multiselect("Selecione o(s) processo(s)", pd.Series(processos),key='proc')
quantities = st.number_input("Quantidade (pç)",key='qt')
volume = st.number_input("Volume da peça (Kg)", key='v')
new_ped = {'Cliente':client,'Item':its,'Artigo':article,'Processos':processes, 'Quantidade(pç)':quantities,'Volume(Kg)':volume}
if st.form_submit_button("Cadastrar :white_check_mark:"):
action(client,quantities,volume,new_ped)
# check
st.write(ped)