3

I have been trying to create a web dashboard with streamlit. The error after running a segment comes to be, " There are multiple identical st.button widgets with the same generated key. "

I am attaching a section of my code below

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

I would appreciate the help. Thank you

Aayush Kaushal
  • 101
  • 2
  • 2
  • 10

1 Answers1

3

Per the docs: https://docs.streamlit.io/en/stable/api.html#streamlit.button

key (str) – An optional string to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.

By not providing a key argument, all widgets have the same None key value. Set a unique value for the key keyword argument in each if statement to fix the error.

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
Randy Zwitch
  • 1,994
  • 1
  • 11
  • 19
  • I can't seem to figure out what to put as unique values. I've tried variables, numbers, etc. – Aayush Kaushal Jul 30 '20 at 08:59
  • 1
    Added working code snippet. It's better to have the buttons defined outside of the interface. The above code is an infinite loop since I don't know `analyze` does, so you'll need to terminate this yourself. – Randy Zwitch Jul 30 '20 at 17:01