-
Notifications
You must be signed in to change notification settings - Fork 87
Open
Labels
status:needs-triageHas not been triaged yetHas not been triaged yettype:enhancementRequests for feature enhancements or new featuresRequests for feature enhancements or new features
Description
Checklist
- I have searched the existing issues for similar feature requests.
- I added a descriptive title and summary to this issue.
Summary
There is a limitation in the Multi Select item as the class needs to have a set
(which order is not guaranteed in Python).
If you pass a class (ExampleModel
) with a list in the default property using the pydantic Field
class, Streamlit works like a charm, but if you pass an instance (ExampleModel (...)
) with a list of values for the set (something like a pre-defined sublist of all the possible values) the list does not have the same order as the one in the instance.
Why?
It should be possible to render the component with a list of values in the desired order.
How?
from enum import Enum
from typing import Set
import streamlit as st
from pydantic import BaseModel, Field
import streamlit_pydantic as sp
class SelectionValue(str, Enum):
FOO = "foo"
BAR = "bar"
BAZ = "baz"
@staticmethod
def all() -> list:
return sorted([item.value for item in SelectionValue])
class ExampleModel(BaseModel):
multi_selection: Set[SelectionValue] = Field(
...,
description="Allows multiple items from a set.",
default=SelectionValue.all()
)
model = ExampleModel(multi_selection=[SelectionValue.BAR, SelectionValue.FOO])
data = sp.pydantic_form(key="my_form", model=model)
if data:
st.json(data.model_dump_json())
Additional Context
No response
Metadata
Metadata
Assignees
Labels
status:needs-triageHas not been triaged yetHas not been triaged yettype:enhancementRequests for feature enhancements or new featuresRequests for feature enhancements or new features