2

我一直在尝试使用 streamlit 创建一个 Web 仪表板。运行段后的错误是,“ There are multiple identical st.button widgets with the same generated key.

我在下面附上了我的一段代码

x = 1
while x > 0:
    if st.sidebar.button("1. Mouthshut.com"):
        analyse(df1)
    if st.sidebar.button("2. Bankbazaar"):
        analyse(df2)
    if st.sidebar.button("3. Creditkaro"):
        analyse(df3)
    if st.sidebar.button("4. Appgrooves"):
        analyse(df4)
    st.header("All the websites combined")
    analyse(df)
    if st.sidebar.button("Exit"):
        break

我将不胜感激。谢谢

4

1 回答 1

2

根据文档:https ://docs.streamlit.io/en/stable/api.html#streamlit.button

key (str) -- 一个可选字符串,用作小部件的唯一键。如果省略,将根据其内容为小部件生成一个密钥。相同类型的多个小部件可能不共享相同的键。

通过不提供key参数,所有小部件都具有相同的None键值。key在每个 if 语句中为关键字参数设置一个唯一值以修复错误。

x = 1

b1 = st.sidebar.button("1. Mouthshut.com", key="1")
b2 = st.sidebar.button("2. Bankbazaar", key="2")
b3 = st.sidebar.button("3. Creditkaro", key="3")
b4 = st.sidebar.button("4. Appgrooves", key="4")
b5 = st.sidebar.button("Exit", key="5")

while x > 0:
    if b1:
       # analyse(df1)
       pass
    if b2:
       # analyse(df2)
       pass
    if b3:
       # analyse(df3)
       pass
    if b4:
       # analyse(df4)
       pass

    st.header("All the websites combined")
    #analyse(df)

    if b5:
        break
于 2020-07-29T16:58:29.877 回答