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
Copy file name to clipboardExpand all lines: README.md
+74-42Lines changed: 74 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
This repository contains the minimal set of code required to create your own custom Dash component.
4
4
5
5
To create your own Dash component:
6
+
6
7
1. Fork this repo
7
8
2. Find-and-replace:
8
9
1.`my_dash_component` with your component library name.
@@ -11,61 +12,92 @@ To create your own Dash component:
11
12
4.`my-license` with your license (e.g. `MIT`)
12
13
5. Rename the folder `my_dash_component/` with your component library name
13
14
3. Install the dependencies:
14
-
```
15
-
npm install
16
-
```
17
-
4. Open up the JavaScript demo environment:
18
-
```
19
-
npm run start
20
-
```
21
-
5. Write your component code in `src/lib/components`. There is a sample component called `ExampleComponent.react.js` that you can use for inspiration. The demo app is in `src/demo` and you will import your example component code into your demo app.
22
-
6. Test your code in a Python environment:
23
-
1. Build your code
15
+
24
16
```
25
-
npm run build:js-dev
26
-
npm run build:py
17
+
npm install
27
18
```
28
-
2. Run and modify the `usage.py` sample dash app:
19
+
20
+
4. Open up the JavaScript demo environment:
21
+
29
22
```
30
-
python usage.py
23
+
npm run start
31
24
```
32
-
7. Create a production build and publish:
25
+
26
+
5. Write your component code in `src/lib/components`. There is a sample component called `ExampleComponent.react.js` that you can use for inspiration. The demo app is in `src/demo` and you will import your example component code into your demo app.
27
+
28
+
6. <span id="customcss">Add custom styles to your component:</span> Add custom CSS files to your distribution folder (`my_dash_component`) and make sure to reference them in `MANIFEST.in` for them to be properly included at publishing time.
29
+
30
+
7. Test your code in a Python environment:
31
+
1. Build your code
32
+
```
33
+
npm run build:js-dev
34
+
npm run build:py
35
+
```
36
+
2. Run and modify the `usage.py` sample dash app:
37
+
```
38
+
python usage.py
39
+
```
40
+
8. Review your code with [the checklist below](#checklist)
41
+
9. Create a production build and publish:
42
+
33
43
1. Build your code:
34
-
```
35
-
npm run build:js
36
-
npm run build:py
37
-
```
44
+
45
+
```
46
+
npm run build:js
47
+
npm run build:py
48
+
```
49
+
38
50
2. Create a Python tarball
39
-
```
40
-
python setup.py sdist
41
-
```
42
-
This distribution tarball will get generated in the `dist/` folder
51
+
52
+
```
53
+
python setup.py sdist
54
+
```
55
+
56
+
This distribution tarball will get generated in the `dist/` folder
43
57
44
58
3. Test your tarball by copying it into a new environment and installing it locally:
45
-
```
46
-
pip install my_dash_component-0.0.1.tar.gz
47
-
```
48
59
49
-
4. If it works, then you can publish the component to NPM and PyPI:
50
-
```
51
-
npm run publish
52
-
```
53
-
```
54
-
twine upload dist/dash_component-0.0.1.tar.gz
55
-
```
56
-
8. Share your component with the community! https://community.plot.ly/c/dash
60
+
```
61
+
pip install my_dash_component-0.0.1.tar.gz
62
+
```
63
+
64
+
4. Choose how you'd like to serve your library's CSS and JS (locally or via npm):
65
+
66
+
By default, Dash serves the component library's CSS and JS from the remote unpkg CDN. Publishing your component to NPM will make the JavaScript bundles available there. To publish to npm:
57
67
58
-
# More details
59
-
- Include CSS files in your distribution folder (`my_dash_component`) and reference them in `MANIFEST.in`
60
-
- The `tests` folder contains a sample integration test. This will run a sample Dash app in a browser. Run this with:
68
+
```
69
+
npm run publish
70
+
```
71
+
72
+
If you choose not publish the component's package to NPM you'll need to set the `serve_locally` flags in `usage.py` to `True`. We will eventually make `serve_locally=True` the default, [follow our progress in this issue](https://github.com/plotly/dash/issues/284).
73
+
74
+
5. Publish your component to PyPI:
75
+
76
+
```
77
+
twine upload dist/dash_component-0.0.1.tar.gz
78
+
```
79
+
80
+
10. [Share your component with the community!](https://community.plot.ly/c/dash)
- You've tested your component on the Python side by creating an app in `usage.py` ? Do all of your component's props work when set from the back-end? Should all of them be settable from the back-end or are some only relevant to user interactions in the front-end?
87
+
- The Dash team uses integration tests extensively, and we highly encourage you to write tests for the main functionality of your component. In the `tests` folder of the boilerplate, you can see a sample integration test. By launching it, you will run a sample Dash app in a browser. You can run the test with:
61
88
```
62
89
python -m tests.test_render
63
90
```
64
-
The Dash team uses these types of integration tests extensively. Browse the Dash component code on GitHub for more examples of testing (e.g. https://github.com/plotly/dash-core-components)
65
-
- Publishing your component to NPM will make the JavaScript bundles available on the unpkg CDN. By default, Dash servers the component library's CSS and JS from the remote unpkg CDN, so if you haven't published the component package to NPM you'll need to set the `serve_locally` flags to `True`. We will eventually make `serve_locally=True` the default, [follow our progress in this issue](https://github.com/plotly/dash/issues/284).
66
-
- Watch the [component boilerplate repository](https://github.com/plotly/dash-component-boilerplate) to stay informed of changes to our components.
91
+
[Browse the Dash component code on GitHub for more examples of testing.](https://github.com/plotly/dash-core-components)
92
+
93
+
## Quick code scan
67
94
95
+
- Are all the css files to be used [referenced in `MANIFEST.in`](#customcss)?
96
+
- Did you [add react docstrings](https://github.com/plotly/dash-docs/blob/master/tutorial/plugins.py#L45) to explain each prop set on your component?
68
97
69
98
# More Resources
70
-
- Learn more about Dash: https://dash.plot.ly
71
-
- View the original component boilerplate: https://github.com/plotly/dash-component-boilerplate
99
+
100
+
- Learn more about Dash: https://dash.plot.ly
101
+
- View the original component boilerplate: https://github.com/plotly/dash-component-boilerplate
102
+
103
+
Watch the [component boilerplate repository](https://github.com/plotly/dash-component-boilerplate) to stay informed of changes to our components.
0 commit comments