-
Notifications
You must be signed in to change notification settings - Fork 3
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
FYI. Panel is adding dataclass conversion. Also Pydantic -> Parameterized #28
Comments
I've tried to achieve almost feature parity. What is missing is BaseModel attributes and pandas intervals. BaseModels will be added later. I did not understand the pandas intervals support. If you see other missing things please let me know. Thx. import pydantic
import panel as pn
from typing import List
from pydantic_panel.dispatchers import infer_widget
from datetime import datetime, date
import numpy as np
import pandas as pd
pn.extension("tabulator")
class ChildModel(pydantic.BaseModel):
name: str = "child"
class SomeModel(pydantic.BaseModel):
name: str = "some model"
child_field: ChildModel = ChildModel()
date_field: date = date(2024,1,2)
dateframe: pd.DataFrame = pd.DataFrame({"x": [1], "y": ["a"]})
datetime_field: datetime = datetime(2024,1,1)
dict_field: dict = {"a": 1}
float_field: float = 42
int_field: int = pydantic.Field(default=2, lt=10, gt=0, multiple_of=2)
list_field: list = [1, "two"]
nparray_field: np.ndarray = np.array([1, 2, 3])
str_field: str = pydantic.Field(default = "to", min_length=2, max_length=10)
tuple_field: tuple = ("a", 1)
class Config:
arbitrary_types_allowed = True # to allow np.array
model = SomeModel()
pydantic_panel_editor = pn.panel(model, sizing_mode="fixed") # Pydantic(model).layout[0]
print(type(pydantic_panel_editor))
panel_editor = pn.Param(pn.dataclass.to_parameterized(model))
pn.Row(
pydantic_panel_editor,
panel_editor,
).servable() |
Thank you @MarcSkovMadsen, thats awesome! |
I will put a link here once its released. |
See holoviz/panel#6912
The text was updated successfully, but these errors were encountered: