streamlit: Exception raised when using multiselect with enums
Summary
Get “streamlit.errors.StreamlitAPIException: Every Multiselect default value must exist in options” when changing values in a multiselect based on a list of enums
Steps to reproduce
Code snippet:
import streamlit as st
from enum import Enum
class Colors(Enum):
yellow = 1
blue = 2
selected_colors = st.multiselect(
"choose colors",
list(Colors),
)
If applicable, please provide the steps we should take to reproduce the bug:
- Launch the streamlit
- Modify a value in the multiselect
- The exception should be raised in the logs
Expected behavior:
No exception should be raised
Actual behavior:
The streamlit exception “Every Multiselect default value must exist in options” is raised in the logs only (not the front).
Is this a regression?
No, I checked streamlit 1.3, 1.7, 1.10, and they had the same issue.
Debug info
- Streamlit version: version 1.7.0
- Python version: 3.9.11
- Using PyEnv
- OS version: Ubuntu 20.04
- Browser version: Chrome Version 103.0.5060.53
Additional information
Only works with enums, not with value list.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (8 by maintainers)
Yep, that makes sense. If you’re using a DATAclass I think it makes sense to use cache_DATA (which serializes) rather than cache_resource (which doesn’t).