Skip to content
Advertisement

Streamlit, Python, and Pandas: Duplicate keys and writing

With Python and Streamlit I’m build apps to assist teachers grading essays. In this segment of the app the user is provided with all the student submissions as .txt files. These files are displayed on the main screen, and users scroll down to display additional texts. In a sidebar there are input fields for entering in comments and grades for each individual txt. The layout for the app is below:

enter image description here

So far so good. However, I’m at a loss to figure out how to capture the output from the sidebar radio buttons and number inputs into a csv with pandas. Here’s my working code below:

JavaScript

However, when I click on button1 to write the output I receive the following error:

DuplicateWidgetID: There are multiple identical st.radio widgets with key='TXTsfeedback_0.txt'. To fix this, please make sure that the key argument is unique for each st.radio you create.

JavaScript

I thought I had set up individual keys within the display_engagement function, but it appears something is amiss. Any ideas or suggestion to resolve this, or to structure this differently? All advice and assistance appreciated.

Advertisement

Answer

I modified your code a bit, but here’s the general solution. There were a few problems.

Problem 1: This made it so that only one item in your list was being passed to the unique key (print off the txts in streamlit and you will see what I mean)

JavaScript

Problem 2: You need to allow the user to generate the data dynamically as a form so that it is all passed at once.

Problem 3: You need to access the unique key in streamlit’s session state.

Problem 4: You need to append to the existing DataFrame

The code below works and it should give you the framework to finish up your app. By the way, super cool idea! I tried to keep a lot of your syntax the sam

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement