ipywidgets-jsonschema
allows you to generate a widget form from an existing schema that follows th JSON Schema specification. We first define a schema:
schema = {
"type": "object",
"properties": {
"name": {"type": "string", "title": "Name"},
"food": {
"type": "array",
"items": {"type": "string"},
"title": "Preferred Food",
},
},
}
Generating the widget form for it and visualizing it in Jupyter is as simple as this:
from ipywidgets_jsonschema import Form
form = Form(schema)
form.show(width="500px")
To get access to the current data, we can use the data
property of form
:
form.data
The data displayed in the widget can also be live-updated by setting the data
property:
form.data = {"name": "Me"}