我在我的Streamlit应用程序侧边栏中有一个多选框。以下不失一般性:
- 我有10个选项可以放在这个多选框中(这些数字是1...10)
- 用户可能不能同时选择
1
和2
因此,如果选择了1
,我想将2
从可选项列表中删除,但是Streamlit似乎没有这种功能,所以我尝试将其包装在循环中,但也失败了(DuplicateWidgetID: There are multiple identical st.multiselect widgets with the same generated key.
):
options = [1,2,3,4,5,6,7,8,9,10]
space = st.sidebar.empty()
answer, _answer = [], None
while True:
if answer != _answer:
answer.append(space.multiselectbox("Pick a number",
options,
default=answer
)
)
options = [o for o in options if o not in answer]
if 1 in options:
if 2 in options: options.remove(2)
if 2 in options:
if 1 in options: options.remove(1)
_answer = answer[:]
你有什么想法可以实现这个目标吗?