You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
explicit Components classes to allow autocomplete #150
metadata.zip
Currently, the Dash components classes are generated only at runtime. Therefore, it is not possible to get autocomplete feature or doc/help contextual hints in IDE (e.g. pycharm).
I would propose to explicit the classes as a real python module and so convert the metadata.json in a metadata.py that could be imported in a standard way.
It could also ease the debugging when adapting these component classes to implement the different TODOs in the code.
I have slightly adapted the component_loader.py as well as the __init__.py of the dash_core_components and dash_html_components to achieve this.
You can find in attachements the resulting metadata.py for both modules.
As this requires changes in different repos (dash but also the dash_*_components), I haven't yet done a PR on this.
If you find the approach valuable, I am ready to follow your guidelines on how to push the changes.
sorry, it wasn't pushed correctly. You should be able to see them now.
on the approach, I wonder if the metadata.py file should be "compiled" during the development/release cycle (and so included in the source), or generated on the fly (with some caching mechanism that checks metadata.json is newer than metadata.py)
We'll want to explore modifying this step so that it generates python code. Note that this template for the component code is already written - we'll just need to convert it from an exec to a file write:
We'll want to create a function like load_components that will generate the code for each component, from a metadata.json file, and write it to the appropriate folder. Calling the function for e.g. dash-core-components should result in a folder structure like:
2. Modify the dash-components-archetype build step
This is the starter package that is used to generate Dash packages from React.js code. Each component library is initialized from this repository and each component library uses the NPM scripts from this component library through a package called "builder".
builder run clean-lib &&
builder run extract-metadata &&
builder run generate-python-components &&
webpack --config=node_modules/dash-components-archetype/config/webpack/webpack.config.dist.js"
"generate-python-components" could look something like:
Manually update the __init__.py files in each package to modify the new __init__.py template (as modified in dash-components-archetype)
Run the new build commands in each package to generate the components
4. Version management
It would be great to not break anyone's code. If a user upgrades dash but doesn't upgrade the new version of dash-core-components, their code shouldn't break.
So, we should keep the existing functions in dash.development.load_components and dash.development.generate_class and add all of this behaviour in new functions.
The new versions of the component libraries should also work with the new version of Dash but also the older versions of Dash. Since generating the components is done as a build-step instead of runtime, the components shouldn't even depend on the version of the dash.development code during runtime.
I don't think this issue was properly closed and it is totally annoying behavior - why would a callback for a button need to be called when the callback has not been clicked yet???
The reference in the push above does not affect in any way this issue.
Activity
sdementen commentedon Oct 29, 2017
I have pushed the changes in the branches classgen-#150 in https://github.com/sdementen/dash/tree/classgen-%23150
https://github.com/sdementen/dash-core-components/tree/classgen-%23150
https://github.com/sdementen/dash-html-components/tree/classgen-%23150
sdementen commentedon Oct 29, 2017
btw, I am not yet happy with the ISUNDEFINED and MUSTBEDEFINED sentinel approach...
chriddyp commentedon Oct 29, 2017
Thanks @sdementen ! Excited to check this out.
I'm having a hard time finding the commits in

classgen-#150- am I looking in the right place?sdementen commentedon Oct 29, 2017
sorry, it wasn't pushed correctly. You should be able to see them now.
on the approach, I wonder if the metadata.py file should be "compiled" during the development/release cycle (and so included in the source), or generated on the fly (with some caching mechanism that checks metadata.json is newer than metadata.py)
chriddyp commentedon Dec 11, 2017
Great idea, I think that's it exactly.
Here is a rough set of steps that would be required for creating these components at build-time vs run-time. cc @alysivji
1. Modify
dash.development.base_component.generate_classanddash.development.component_loader.load_componentsThese functions are called at runtime by the component libraries, see e.g. https://github.com/plotly/dash-core-components/blob/c898d75a1a189943bcf92bc73b95bd08432ddd7d/dash_core_components/__init__.py#L8-L11
They consume a
metadata.jsonfile that is included in the package folder (e.g. https://github.com/plotly/dash-core-components/blob/c898d75a1a189943bcf92bc73b95bd08432ddd7d/dash_core_components/metadata.json#L1-L26)Note that
metadata.jsonis generated from comments in the component author's React.js code withreact-docgenin theextract-metadatastep in the package.json: https://github.com/plotly/dash-components-archetype/blob/67912c1a56a58fa68e1f00c90136af1d7ae444d9/package.json#L37We'll want to explore modifying this step so that it generates python code. Note that this template for the component code is already written - we'll just need to convert it from an
execto a file write:dash/dash/development/base_component.py
Lines 198 to 255 in 3cd6a78
We'll want to create a function like
load_componentsthat will generate the code for each component, from ametadata.jsonfile, and write it to the appropriate folder. Calling the function for e.g.dash-core-componentsshould result in a folder structure like:2. Modify the
dash-components-archetypebuild stepThis is the starter package that is used to generate Dash packages from React.js code. Each component library is initialized from this repository and each component library uses the NPM scripts from this component library through a package called "
builder".We'll need to modify these package's scripts to generate the python code. The command for this script will live here: https://github.com/plotly/dash-components-archetype/blob/67912c1a56a58fa68e1f00c90136af1d7ae444d9/package.json#L29-L43 and we can call it something like
"generate-python-components"and we'll need to stick it after eachextract-metadatascript.For example,
build-disthttps://github.com/plotly/dash-components-archetype/blob/67912c1a56a58fa68e1f00c90136af1d7ae444d9/package.json#L33will become
"generate-python-components"could look something like:where the
generate_componentsfunction might look for a localmetadata.jsonfile.3. Modify the
dash-components-archetype__init__.pyThe standard component
__init__.pycalls the component loader: https://github.com/plotly/dash-core-components/blob/c898d75a1a189943bcf92bc73b95bd08432ddd7d/dash_core_components/__init__.py#L6-L11. We'll need to remove this and add whatever is necessary so that the standard imports work:4. Modify the
dash-html-componentsanddash-core-componentsto use the patches indash-components-archetypeanddashdash-components-archetypein each package (e.g. https://github.com/plotly/dash-core-components/blob/c898d75a1a189943bcf92bc73b95bd08432ddd7d/package.json#L28)__init__.pyfiles in each package to modify the new__init__.pytemplate (as modified indash-components-archetype)4. Version management
It would be great to not break anyone's code. If a user upgrades
dashbut doesn't upgrade the new version ofdash-core-components, their code shouldn't break.So, we should keep the existing functions in
dash.development.load_componentsanddash.development.generate_classand add all of this behaviour in new functions.The new versions of the component libraries should also work with the new version of Dash but also the older versions of Dash. Since generating the components is done as a build-step instead of runtime, the components shouldn't even depend on the version of the
dash.developmentcode during runtime.5. Testing
dash.development. We'll need to keep those so that we can maintain backwards compatibility: https://github.com/plotly/dash/blob/master/tests/development/test_component_loader.py#L103-L108dash/tests/developmentfor the new behaviour.znd4 commentedon May 24, 2018
Sorry, did you mean to close this issue when you closed #226 ?
rmarren1 commentedon Oct 18, 2018
This was added in #276
Issue148 - `0` children regression in dash==0.40.0 (#150)
Fix LICENSE for dashHtmlComponents install on Windows (plotly#150)
Fix LICENSE for dashHtmlComponents install on Windows (plotly#150)
Fix LICENSE for dashHtmlComponents install on Windows (#150)
michael72 commentedon Aug 14, 2023
I don't think this issue was properly closed and it is totally annoying behavior - why would a callback for a button need to be called when the callback has not been clicked yet???
The reference in the push above does not affect in any way this issue.