I am working with streamlit and python to create webpage of our code but it is showing me some error to fix this error I give different keys to every input arguments but still it showing me the error.
I have given the different keys to every input but it showing in error as below:
DuplicateWidgetID: There are multiple identical st.selectbox widgets with key='155'.
To fix this, please make sure that the key argument is unique for each st.selectbox you create.
Traceback:
File "C:\Users\jaiklen\Desktop\IP_Assignment_2\web.py", line 29, in <module>
query = st.selectbox("Please Enter Your Query Number or enter -1 to exit: ",[-1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],key = "155")
Below is my python code with streamlit:
import json
import streamlit as st
import a2 as a
st.title("Welcom to our database")
st.write("There are some queries below :")
st.write("1. read_data_from_file")
st.write("2. filter_by_first_name")
st.write("3. filter_by_last_name")
st.write("4. filter_by_full_name")
st.write("5. filter_by_age_range")
st.write("6. count_by_gender")
st.write("7. filter_by_address")
st.write("8. find_alumni")
st.write("9. find_topper_of_each_institute")
st.write("10. find_blood_donors")
st.write("11. get_common_friends")
st.write("12. is_related")
st.write("13. delete_by_id")
st.write("14. add_friend")
st.write("15. remove_friend")
st.write("16. add_education")
query = 0
while(query != -1):
query = st.selectbox("Please Enter Your Query Number or enter -1 to exit: ",[-1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],key = "155")
records = a.read_data_from_file()
if(query == 2):
first_name = st.text_input("Enter the first name",key = "2")
st.write(a.filter_by_first_name(records, first_name))
elif(query == 3):
last_name = st.text_input("Enter the last name",key = "3")
st.write(a.filter_by_last_name(records, last_name))
elif(query == 4):
full_name = st.text_input("Enter the full name",key = "4")
st.write(a.filter_by_full_name(records, full_name))
elif(query == 5):
min_age = int(st.text_input("Enter the minimum age",key = "5"))
max_age = int(st.text_input("Enter the maximum age",key = "6"))
st.write(a.filter_by_age_range(records, min_age, max_age))
elif(query == 6):
#full_name = st.text_input("Enter the full name")
st.write(a.count_by_gender(records))
elif(query == 7):
address = {}
house_no = st.text_input("Enter house number or leave empty: ",key = "7")
block = st.text_input("Enter block or leave empty: ",key = "8")
town = st.text_input("Enter town or leave empty: ",key = "9")
city = st.text_input("Enter city or leave empty: ",key = "10")
state = st.text_input("Enter state or leave empty: ",key = "11")
pin_code = st.text_input("Enter pin code or leave empty: ",key = "12")
if(len(house_no) != 0):
address["house_no"] = int(house_no)
if(len(block) != 0):
address["block"] = block
if(len(town) != 0):
address["town"] = town
if(len(city) != 0):
address["city"] = city
if(len(state) != 0):
address["state"] = state
if(len(pin_code) != 0):
address["pin_code"] = int(pin_code)
st.write(len(a.filter_by_address(records, address)))
elif(query == 8):
institute_name = st.text_input("Enter the institute name",key = "13")
st.write(a.find_alumni(records, institute_name))
elif(query == 9):
#full_name = st.text_input("Enter the full name")
st.write(a.find_topper_of_each_institute(records))
elif(query == 10):
receiver_person_id = int(st.text_input("Enter the full name",key = "14"))
st.write(a.find_blood_donors(records, receiver_person_id))
elif(query == 11):
list_of_ids = list(map(int,st.text_input("Enter the full name",key = "15").split()))
st.write(a.get_common_friends(records, list_of_ids))
elif(query == 12):
person_id_1 = int(st.text_input("Enter the person id 1",key = "16"))
person_id_2 = int(st.text_input("Enter the person id 2",key = "17"))
st.write(a.is_related(records, person_id_1, person_id_2))
elif(query == 13):
person_id = int(st.text_input("Enter the person id",key = "18"))
records = a.delete_by_id(records, person_id)
elif(query == 14):
person_id = int(st.text_input("Enter the person id",key = "19"))
friend_id = int(st.text_input("Enter the friend id",key = "20"))
records = a.add_friend(records, person_id, friend_id)
elif(query == 15):
person_id = int(st.text_input("Enter the person id",key = "21"))
friend_id = int(st.text_input("Enter the friend id",key = "22"))
records = a.remove_friend(records, person_id, friend_id)
elif(query == 16):
person_id = int(st.text_input("Enter the person id",key = "23"))
institute_name = st.text_input("Enter the institute name",key = "24")
ongoing = bool(st.text_input("If ongoing enter True else entre False",key = "25"))
percentage = float(st.text_input("Enter percentage if ongoing False, else enter 0",key = "26"))
records = a.add_education(records, person_id, institute_name, ongoing, percentage)
I anyone knows where is the error please let me know. and thank you to at least read my problem.