python - DuplicateWidgetID:有多个相同的 st.selectbox 小部件
问题描述
我正在使用 streamlit 和 python 来创建我们的代码网页,但它向我显示了一些错误来修复此错误我为每个输入参数提供了不同的键,但它仍然向我显示错误。
我为每个输入提供了不同的键,但它显示错误如下:
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")
下面是我的带有流光的 python 代码:
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)
我有人知道错误在哪里,请告诉我。并感谢您至少阅读我的问题。
解决方案
只需将每个替换.
为[.]
:
ip=ip.replace(".","[.]")
推荐阅读
- python - 如何在没有 Http 错误 500 的情况下在 Django 中设置 Debug=False 和 Allowed_hosts
- python - 熊猫用另一列中的多个字符串创建一个新列
- unity3d - 获取父对象的坐标
- github - 无法在推送到生产时进行版本碰撞
- python - 向量化numpy数组的递归函数,其中每个元素都依赖于之前的所有元素
- python - 我可以指定要在计划任务(crontab)中运行的环境吗
- java - javafx中如何实现UNDECORATED + UTILITY的效果?
- asterisk - 通过“EXEC”运行 AMD 或其他星号应用程序时的星号 EAGI 音频
- php - 登录 Laravel 后如何存储 url 参数并使用它来重定向(使用 Inertia 和 Vue)?
- java - 在请求的时间内无法获得锁