-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Multiselect check for defaults goes wrong if not a list #1397
Copy link
Copy link
Closed
Labels
type:bugSomething isn't working as expectedSomething isn't working as expected
Description
Summary
When using st.multiselect(), there's an error being thrown out if default values are given in a tuple instead of a list. See additional info for a solution. I'm happy to do a PR if you're ok with my point.
Steps to reproduce
- Create an
app.pywith the following:
import streamlit as st
INTENSITIES = ("a", "b", "c")
st.multiselect(
label="Choose among:",
options=INTENSITIES,
default=INTENSITIES,
)- Now run
streamlit run app.py.
Expected behavior:
The code above should work and print the following:
It does work if given list objects as in:
st.multiselect(
label="Choose among:",
options=list(INTENSITIES),
default=list(INTENSITIES),
)Actual behavior:
Error shows:
StreamlitAPIException: Every Multiselect default value must exist in optionsIs this a regression?
Not sure about this. Didn't try before.
Debug info
- Streamlit version: 0.58.0
- Python version: Python 3.6.9 :: Anaconda, Inc.
- Using Conda
- OS version: macOS Mojave 10.14.6
- Browser version: Google Chrome 81.0.4044.92
Additional info
Code responsible seems to be here when casting to list:
if not isinstance(default_values, list):
default_values = [default_values]
Should rather be:
if not isinstance(default_values, list):
default_values = list(default_values)
Otherwise, in the tuple case, ("a", "b", "c") is converted to [("a", "b", "c")] hence the error.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type:bugSomething isn't working as expectedSomething isn't working as expected
