catalystneuro/json-schema-to-dash-forms

code requires update...

Opened this issue · 3 comments

Hello,

would love to use your package and examples, however it is outdated, with newer bootstrap and dash versions.

would it possible for you to update your package

Hello,

would love to use your package and examples, however it is outdated, with newer bootstrap and dash versions.

would it possible for you to update your package

Came here for the same question. Any plans on updating the package? Is there some kind of roadmap on things to do?

newlog commented

To be more explicit, this is one of the errors that are triggered on execution.

  File "<path>", line 8, in <module>
    from json_schema_to_dash_forms import SchemaFormContainer
  File "json_schema_to_dash_forms/__init__.py", line 1, in <module>
    from .forms import SchemaFormContainer
  File "json_schema_to_dash_forms/forms.py", line 17, in <module>
    class SchemaFormItem(dbc.FormGroup):
                         ^^^^^^^^^^^^^
  File "dash_bootstrap_components/__init__.py", line 50, in __getattr__
    raise AttributeError(
AttributeError: FormGroup was deprecated in dash-bootstrap-components version 1.0.0. You are using 1.4.1. For more details please see the migration guide: https://dash-bootstrap-components.opensource.faculty.ai/migration-guide/. Did you mean: 'CardGroup'?
newlog commented

A list of fixes I had to do to get me to a point where it seems it might execute.

Deprecated components:

  • Replace FormsGroup by Form.
  • Remove InputGroupAddon objects and just pass whatever it's inside of the InputGroupAddon to the parent's children parameter.
  • Replace all references of "checked" to "value".
  • Replace all references of "bs_size" to "size".

It is assumed that the instance variable "schema" in SchemaForm class will always be a dictionary, even in the example of the author, it also happens to be a list. Here:

class SchemaForm(dbc.Card):
    """
    Form generated by JSON Schema.
    """

    def __init__(self, schema, key, container=None, parent_form=None):
        super().__init__([])

        self.schema = schema
        self.owner_class = schema.get('tag', '')
        self.parent_form = parent_form
        self.skiped_forms = []

And it fails with the schema example, here:

(...)
	    		"subform_children_array_example": {
	    			"type": "array",
		            "description": "subforms children array w/ size defined by min/max items and referenced by definitions",
		            "minItems": 2,
		            "maxItems": 2,
		            "items": [{"$ref":  "#/definitions/ChildrenExample"}]
	    		}
	    	}
	    }
      }
    }
  },
	"definitions": {
	    "ChildrenExample": {
	      "type": "object",
	      "required": ["string"],
	      "properties": {
	        "string": {
	          "type": "string",
	          "description": "children string field"
	        },
	        "description": {
	          "type": "number",
	          "description": "children numeric field"
	        }
	      }
	    }
	}
}

For now, I won't use subforms/refs in that manner.

Finally, it seems you can't pass DashBlueprint to parent_app when instantiating SchemaFormContainer . I fixed that by using the get_app() helper from dash (not positive it will always work in my case).

By doing all those changes you get the UI to render.