Updating a key/value pair, using user input, in a for loop in Streamlit


I am trying to get user input to update a key / value pair in a for loop (code reproduced below). However, I understand that whenever a widget interection takes place stream lit runs the code from the top again. Is there a workaround this?

for item in unmatched_column_names:
    text_input_key = text_input_key + 1
    value=st.text_input(label='Please rename the column to an existing data field in the template',key=str(text_input_key))

Hi @rohit_somani,

First let me welcome you to the Streamlit Community! :partying_face: :tada: :partying_face: :tada: :partying_face: :tada:

We are currently developing a programmable state that will make this easier, but it has not launched yet! However, many others in the community have made some workarounds for this that you may find helpful. I have added some links below:

Multi-page app with session state
Alternative implementation of session state

To me based on you code snippet, it looks like you are using a pandas dataframe and your wanting to change the names of some columns based on the text_input and value, is that correct?

I’m not entirely sure that this will do as a work around, but in the past I have been able to pickle changed files and load the new updated file into my streamlit app to get around the re-running of the script. Now if this is a large data set then you may not want to reload every time, but you might be able to pickle just the names of the columns and update those names in your database every time the user changes a column name.

Good luck and Happy Streamlit-ing!