maxfordham / ipyautoui

create ipywidgets user input form pydantic model or jsonschema
https://maxfordham.github.io/ipyautoui/
38 stars 5 forks source link

✨ make autoui compatible with solara #289

Open tharwan opened 4 months ago

tharwan commented 4 months ago

Is your feature request related to a problem? Please describe. it would be great to use autoui in solara

Describe the solution you'd like

import solara as sl
from ipyautoui import AutoVjsf
from pydantic import BaseModel

class SolaraApp(BaseModel):
    name: str
    value: int

@sl.component
def page():
    AutoVjsf.element(schema=SolaraApp.schema(), value=dict(name="foo", value=12))

should display the correct form.

Describe alternatives you've considered I tried to use it in its current form and get the following error: AttributeError: property 'schema' of 'AutoVjsf' object has no setter

Additional context solara seams like a really great way to build UIs with ipywidgets.

jgunstone commented 4 months ago

agree this would be great... not 100% about everything that is involved... you could try using Vjsf rather than AutoVjsf i.e. from ipyautoui.autovjsf import Vjsf as this has a schema trait....? the AutoVjsf just adds stuff like the save button bar and show / hide raw etc., but Vjsf is doing all the work in terms of making the form

tharwan commented 4 months ago

I will give it a try. Is there something similar for the ipywidget based version as well?

jgunstone commented 4 months ago

currently in AutoObject (AutoUi = autoui is now just a builder function that returns AutoObject typically) schema is not a trait so the form would not update on change: https://github.com/maxfordham/ipyautoui/issues/192. I assume that this would be a min requirement of solara to work in the way you are hoping ...

solara also wraps ipywidget based syntax in react-like syntax they use in reacton https://reacton.solara.dev/en/latest/libraries/. I think for ipyautoui to work natively in solara we'd need to find a way to do that. I think that this relies on the objects using traits to instantiate and control the widget state... which broadly speaking ipyautoui does... but I think we'd need to dig into reacton's requirements a little more to try and make them work together.

I created a branch/ PR https://github.com/maxfordham/ipyautoui/pull/291 where I did an initial test in making an ipyautoui reacton wrapper... it doesn't work... but some things do work...

I'd love to see this progressed, but realistically I'm not gonna be able to put much time towards at least for the foreseeable... If you're interested / willing to have a look in more detail I'll try and help where I can.

tharwan commented 4 months ago

Thanks for the work!

After working some more on our prototype, we found that working with the vue components is the better fit for solara. So probably it is not worth the effort to work in the ipywidgets version in the first place.

The vjsf component works just finde even with dynamic schema changes.

jgunstone commented 4 months ago

glad its working for you with Vjfs I'm gonna re-open the issue as this is something I'd like to target in the future...