I got to a point that I need to generate almost the same widget multiple times. But then, I run into some odd issues. Here is the stripped result.
import streamlit as st import uuid ELEMENTS = ["foo", "bar", "hello", "world"] def bar(key=str(uuid.uuid4())): selected = st.selectbox("Yo Yo:", ELEMENTS, key=key) return selected st.write("# ABC") selected1 = bar() st.write(selected1) selected2 = bar("bbb") st.write(selected2)
It turns out, that the first instance of the
selectbox doesn’t work well. It always gets the default value. Why is that? How can I write a function wraps a
selectbox or any other widget. Note that ultimately, I will have more logic in the function preparing the widget. One this is for sure, I need to have the same
element… That’s why I’m using a
uuid for the
key. What do you think?