Summary
I want to set “key” property in multiselects, because it provides me the convenience related to session_state handling.
But, if the input to multiselect is empty, rendering the multiselect fails with the following error:
StreamlitAPIException: Every Multiselect default value must exist in options
Steps to reproduce
Code snippet:
facts = []
st.sidebar.multiselect(
label="Facts:",
options=[x.id for x in facts],
key="selected_facts", # if I comment out this line, it works as expected
)
Expected behavior:
No error is returned.
The input is collected from a backend, it usually is not empty, but it may happen that it’s empty.
I expect the same multiselect declaration works for both scenarios.
Debug info
- Streamlit version: 1.20.0
- Python version: 3.10
- Using PipEnv
- OS version: Ubuntu 22.04
- Browser version: Chrome latest