jmosbacher / pydantic-panel

Edit pydantic models with widgets from the awesome Panel package
MIT License
24 stars 3 forks source link

Support from_attribute similar to Panel widgets .from_param #4

Closed MarcSkovMadsen closed 2 years ago

MarcSkovMadsen commented 2 years ago

With Panel you can (see)

widget = pn.widgets.IntSlider.from_param(Example.param.unbounded_int, start=0, end=100)

Being able to create single widgets from Pydantic Model Attributes would be very useful as well. Some method like the below would be useful

widget = from_attribute(pn.widgets.IntSlider, example, "unbounded", start=0, end=100)
jmosbacher commented 2 years ago

Im not sure I understand what you are proposing. Do you mean to split up the logic inside the for loop of pydantic_widgets to a separate function so people can use the function to get a single widget instead of a dictionary with widgets for each field? Or do mean to just make this function more accessible to users that want to create the widgets and modify them themselves?

MarcSkovMadsen commented 2 years ago

I actually don't understand the implementation of pydantic-panel yet. But what I propose is to expose functionality to create a single widget.

The motivation is that I have often seen with Param that users ask for help to define or get hold of a single widget.

jmosbacher commented 2 years ago

Ok, I guess I can add documentation for how to do this and maybe some more user friendly docstrings. Currently this function is just used internally.

jmosbacher commented 2 years ago

This is now solved via Pydantic pane supporting arbitrary python objects. e.g. for the above example pn.panel(example, start=0, end=100) works.