Problem with List.pop() breaking the text_input component

Hi
I’m new to Streamlit. I have noticed a strange problem in my app. Basically, i load a csv file and want to do a quiz (question / answer) based on the content.
Once the file is loaded, i create a list of word from which I want to pop() the first element for the first question and so one.
The problem is that as soon as i call pop(), the text_input stop working. I’ve noticed this strange behaviour only when my list is created from the dictionnary loaded from the CSV.
Any idea what could cause this?

  1. Are you running your app locally or is it deployed?
  • Executed locally
  1. If your app is deployed:
  • N/A
  1. Share the link to your app’s public GitHub repository (including a [requirements file]
  1. Share the full text of the error message
  • No error messages, the text_input just doesn’t supply any value on enter
  1. Share the Streamlit and Python versions.
    Python version: 3.11.6
    Streamlit version: 1.29.0

Can you provide a minimal reproducible code?

Hi Ferdy
Thank you for helping me in this topic.
The code that is in the Github link. Let me know if you can access it, it should, I’ve made it public.

I’ve misinterpreted the source. It is not pop() but rather accessing that list i create from the file read. I’ve done some more testing yesterday, redid the code to use an object holding all this information and have the same behaviour.

I’ve put Steamlit in debug, and see this. Note that the last message is a print statement that shows that the text_input does not return a value which is THE problem for me.

Any other mechanism to get this value?

Thanks again for taking the time to help!

2024-01-10 07:18:19.983 Received the following back message:
rerun_script {
widget_states {
widgets {
id: “$$WIDGET_ID-7087dc428ba823959cfa676944227e95-None”
file_uploader_state_value {
uploaded_file_info {
name: “Mots-Table 1.csv”
size: 40941
file_id: “f401ac88-6d6a-4188-9aa2-5c52bb9143a6”
file_urls {
file_id: “f401ac88-6d6a-4188-9aa2-5c52bb9143a6”
upload_url: “/_stcore/upload_file/0297a171-d6b0-458e-a3c2-e7891fb17a1a/f401ac88-6d6a-4188-9aa2-5c52bb9143a6”
delete_url: “/_stcore/upload_file/0297a171-d6b0-458e-a3c2-e7891fb17a1a/f401ac88-6d6a-4188-9aa2-5c52bb9143a6”
}
}
}
}
widgets {
id: “$$WIDGET_ID-9281d8053efcf45d913b958a5acb8f5b-translatedWordText”
string_value: “111”
}
}
page_script_hash: “d02390c3490891b1a7adec0d26cf9d67”
}

2024-01-10 07:18:19.983 Beginning script thread
2024-01-10 07:18:19.983 Running script RerunData(widget_states=widgets {
id: “$$WIDGET_ID-7087dc428ba823959cfa676944227e95-None”
file_uploader_state_value {
uploaded_file_info {
name: “Mots-Table 1.csv”
size: 40941
file_id: “f401ac88-6d6a-4188-9aa2-5c52bb9143a6”
file_urls {
file_id: “f401ac88-6d6a-4188-9aa2-5c52bb9143a6”
upload_url: “/_stcore/upload_file/0297a171-d6b0-458e-a3c2-e7891fb17a1a/f401ac88-6d6a-4188-9aa2-5c52bb9143a6”
delete_url: “/_stcore/upload_file/0297a171-d6b0-458e-a3c2-e7891fb17a1a/f401ac88-6d6a-4188-9aa2-5c52bb9143a6”
}
}
}
}
widgets {
id: “$$WIDGET_ID-9281d8053efcf45d913b958a5acb8f5b-translatedWordText”
string_value: “111”
}
, page_script_hash=‘d02390c3490891b1a7adec0d26cf9d67’)
2024-01-10 07:18:19.984 Disconnecting files for session with ID 0297a171-d6b0-458e-a3c2-e7891fb17a1a
2024-01-10 07:18:19.984 Sessions still active: dict_keys()
2024-01-10 07:18:19.984 Files: 0; Sessions with files: 0
Items in the word list: 9
User input read: ← Here I should have the value in the text_input

Code:
user_input = st.session_state[‘translatedWordText’]
print("User input read: " + user_input)

Do you have a sample csv file.

Sorry
Sure it’s in the repo now.

Hi @rikgig

Have you tried using alternative methods to pop() that may achieve the same effect.

I use your code in repo and load the csv. In the function,

def read_word_dictionary_from_csv(file):
    word_dict = {}
    with file:
        reader = csv.reader(file)
        for row in reader:
            if len(row) > 0:
                # pronoun, spanish, french, details, five, six, seven = row
                pronoun, spanish, french, details, five, six = row
                word_dict[spanish.strip()] = french.strip()
    return word_dict

I changed
# pronoun, spanish, french, details, five, six, seven = row
to
# pronoun, spanish, french, details, five, six = row
because the csv has only 6 columns.

Now it works.

Hi Ferdy
Ah yes sorry. I changed the structure of that CSV but didn’t updated this small app. I have not shared the complete project… .which I should probably do.
Try typing something in the box, on the “next” iteration, the problem should be seen. I mean, the text_input not submitting any text anymore.

Hi @dataprofessor
Yes. I have re-written the small app and used index to access the list content and I have the same behaviour.
Something strange in happening in the session state. I will share my new code later today and maybe you guys will be able to see what I am doing wrong. I’m pretty sure it’s my fault but can’t figure what I’m doing wrong
Thanks for the help!

Hi

So the app code can be found here:

We see with this one the strange behaviour of the text_input that looses the ability to return the text we enter.

I would be very interested to know what si wrong here.

Thanks again!