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
Populate generated form values from a pydantic model instance #16
Conversation
Add complex_instance_model.py to demonstrate and test the new functionality.
…@HUN220 for finding the issue and suggesting the fix.
Closes #15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this awesome contribution 👍 Implemention looks good and everything in complex_instance_model
works fine. However, there seems to be a problem with the union_field_instance
example.
Ahh, I think I figured out why it is not working. Discriminated unions are only supported since pydantic |
Thanks for the suggestions! In regards to performance, note there there can sometimes be some noticeable lag/jitters when interacting with some of the list value widgets, particularly when the model is large and/or there is multiple models on screen. This is pretty well demonstrated in Clicking the +/- buttons on one of the number widgets within a list (eg. int list, int dict, object list) often results in a noticeable redraw and second or third button clicks are not always honoured in the widgets value. With the I'm not sure if this is an existing issue but the new method of handling lists that is introduced with this PR (where every item is being individually rendered) is possibly making it more noticeable. |
Another aspect I was just thinking about: The union type instance support works great if the |
session value of a widget to initialise its value (if it already exists in the session). This resolves most of the value lag/bounce that can occur with this widget when using the +/- buttons
This simplifies the rendering and resolves much of the UI lag/jerkiness
without the need for discriminator property Differentiate between the two union examples
ok, good news. I believe I've resolved the major lag/jitter issues with the latest commits and ready for another review. Editable data frames would indeed be a great alternative for editing lists/dicts although I imagine it would depend a bit on the data that is being represented. The method included in this PR (now that it works a bit better) might still be preferable for smaller lists (of say 1-5 values) and I was thinking that streamlit's new tabs feature might be a really good option for rendering lists of complex objects (which can individually take up a lot of screen real estate). With a few decent options to choose from the user could decide which method works best using the "format" Field parameter. Also, Union type instances also now work with or without a discriminator field. |
Awesome :) It seems to work a lot better now! And also really like that Union works without
I like that idea :) Indeed, tabs could simplify the UI a lot for complex object lists. And adding a configuration option for how certain properties are rendered ( |
make a note about aliases. To make aliases work here I think will require some more signficant changes
rendering objects in the sidebar
In addition to the fix above I've also cleaned up the list control rendering so its usable within the sidebar. |
What kind of change does this PR introduce?
Description:
This PR adds the capability to provide a pydantic model instance to sp.pydantic_input() and have the generated pydantic widgets be pre-populated with the instance property values.
This allows for full CRUD operations to be performed on pydantic data using streamlit.
I've been tinkering with this and some other changes in my fork and have made good use of it in a couple of projects now and it would be nice to get it merged upstream.
To demonstrate the functionality I've added two additional examples to the playground:
Checklist: