-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the difference between default
and init_value
?
#26
Comments
class User(BaseModel):
id: int
name = 'Jane Doe'
In hindsight, In terms of which value should get passed through to the streamlit widgets when both attributes exist, |
I noticed that if the default value is passed to from typing import Dict
import streamlit as st
from pydantic import BaseModel, Field
import streamlit_pydantic as sp
class ShowcaseModel(BaseModel):
string_dict: Dict[str, str] = Field(
# init_value={"foo": "1.0"},
default={"foo": "bar"},
)
float_dict: Dict[str, float] = Field(
init_value={"foo": 1.0},
)
session_data = sp.pydantic_input(
key="my_input", model=ShowcaseModel, group_optional_fields="sidebar"
)
with st.expander("Current Input State", expanded=False):
st.json(session_data) Is this as expected? |
In the case of dicts, lists and objects I guess its a bug/missing feature. I've added a PR to address it. |
Describe the issue:
Hi, I noticed that there are two fields,
default
andinit_value
, that can be used in Field. May I ask what the difference is between these two fields? It seems that their effects are the same, but is the priority ofinit_value
higher thandefault
?Thank you.
Technical details:
The text was updated successfully, but these errors were encountered: