Skip to content

Commit d00f625

Browse files
Merge pull request #2959 from plotly/add-dash-snippets
Added 11 new Dash Snippets to Python Docs
2 parents f1a716b + 395f76d commit d00f625

11 files changed

+172
-32
lines changed

Diff for: doc/python/builtin-colorscales.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.4.2
9+
jupytext_version: 1.6.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.7.6
2424
plotly:
2525
description: A reference for the built-in named continuous (sequential, diverging
2626
and cylclical) color scales in Plotly.
@@ -74,6 +74,19 @@ import plotly.express as px
7474
print(px.colors.sequential.Plasma)
7575
```
7676

77+
### Continuous Color Scales in Dash
78+
79+
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash`, click "Download" to get the code and run `python app.py`.
80+
81+
Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with <a class="plotly-red" href="https://plotly.com/dash/">Dash Enterprise</a>.**
82+
83+
84+
```python hide_code=true
85+
from IPython.display import IFrame
86+
snippet_url = 'https://dash-gallery.plotly.host/python-docs-dash-snippets/'
87+
IFrame(snippet_url + 'builtin-colorscales', width='100%', height=630)
88+
```
89+
7790
### Built-In Sequential Color scales
7891

7992
A collection of predefined sequential colorscales is provided in the `plotly.colors.sequential` module. Sequential color scales are appropriate for most continuous data, but in some cases it can be helpful to use a diverging or cyclical color scale (see below).

Diff for: doc/python/horizontal-vertical-shapes.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.4.2
9+
jupytext_version: 1.6.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.7.6
2424
plotly:
2525
description: How to add annotated horizontal and vertical lines in Python.
2626
display_as: file_settings
@@ -67,6 +67,19 @@ fig.add_hrect(y0=0.9, y1=2.6, line_width=0, fillcolor="red", opacity=0.2)
6767
fig.show()
6868
```
6969

70+
#### Horizontal and vertical lines in Dash
71+
72+
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash`, click "Download" to get the code and run `python app.py`.
73+
74+
Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with <a class="plotly-red" href="https://plotly.com/dash/">Dash Enterprise</a>.**
75+
76+
77+
```python hide_code=true
78+
from IPython.display import IFrame
79+
snippet_url = 'https://dash-gallery.plotly.host/python-docs-dash-snippets/'
80+
IFrame(snippet_url + 'horizontal-vertical-shapes', width='100%', height=630)
81+
```
82+
7083
#### Adding Text Annotations
7184

7285
[Text annotations](/python/text-and-annotations) can optionally be added to an autoshape

Diff for: doc/python/interactive-html-export.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.3.1
9+
jupytext_version: 1.6.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.8
23+
version: 3.7.6
2424
plotly:
2525
description: Plotly allows you to save interactive HTML versions of your figures
2626
to your local disk.
@@ -56,10 +56,23 @@ fig.write_html("path/to/file.html")
5656
By default, the resulting HTML file is a fully self-contained HTML file which can be uploaded to a web server or shared via email or other file-sharing mechanisms. The downside to this approach is that the file is very large (5Mb+) because it contains an inlined copy of the Plotly.js library required to make the figure interactive. This can be controlled via the `include_plotlyjs` argument (see below).
5757

5858

59+
### HTML export in Dash
60+
61+
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash`, click "Download" to get the code and run `python app.py`.
62+
63+
Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with <a class="plotly-red" href="https://plotly.com/dash/">Dash Enterprise</a>.**
64+
65+
66+
```python hide_code=true
67+
from IPython.display import IFrame
68+
snippet_url = 'https://dash-gallery.plotly.host/python-docs-dash-snippets/'
69+
IFrame(snippet_url + 'interactive-html-export', width='100%', height=630)
70+
```
71+
5972
### Full Parameter Documentation
6073

6174
```python
6275
import plotly.graph_objects as go
6376

6477
help(go.Figure.write_html)
65-
```
78+
```

Diff for: doc/python/mapbox-county-choropleth.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.4.2
9+
jupytext_version: 1.6.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.7.6
2424
plotly:
2525
description: How to make a Mapbox Choropleth Map of US Counties in Python with
2626
Plotly.
@@ -107,6 +107,19 @@ fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
107107
fig.show()
108108
```
109109

110+
### Choropleth maps in Dash
111+
112+
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash`, click "Download" to get the code and run `python app.py`.
113+
114+
Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with <a class="plotly-red" href="https://plotly.com/dash/">Dash Enterprise</a>.**
115+
116+
117+
```python hide_code=true
118+
from IPython.display import IFrame
119+
snippet_url = 'https://dash-gallery.plotly.host/python-docs-dash-snippets/'
120+
IFrame(snippet_url + 'mapbox-county-choropleth', width='100%', height=630)
121+
```
122+
110123
### Indexing by GeoJSON Properties
111124

112125
If the GeoJSON you are using either does not have an `id` field or you wish you use one of the keys in the `properties` field, you may use the `featureidkey` parameter to specify where to match the values of `locations`.

Diff for: doc/python/ml-knn.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.4.2
9+
jupytext_version: 1.6.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.7.6
2424
plotly:
2525
description: Visualize scikit-learn's k-Nearest Neighbors (kNN) classification
2626
in Python with Plotly.
@@ -236,6 +236,19 @@ fig.add_trace(
236236
fig.show()
237237
```
238238

239+
## k-NN classification in Dash
240+
241+
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash`, click "Download" to get the code and run `python app.py`.
242+
243+
Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with <a class="plotly-red" href="https://plotly.com/dash/">Dash Enterprise</a>.**
244+
245+
246+
```python hide_code=true
247+
from IPython.display import IFrame
248+
snippet_url = 'https://dash-gallery.plotly.host/python-docs-dash-snippets/'
249+
IFrame(snippet_url + 'knn-classification', width='100%', height=630)
250+
```
251+
239252
## Multi-class prediction confidence with [`go.Heatmap`](https://plotly.com/python/heatmaps/)
240253

241254
It is also possible to visualize the prediction confidence of the model using [heatmaps](https://plotly.com/python/heatmaps/). In this example, you can see how to compute how confident the model is about its prediction at every point in the 2D grid. Here, we define the confidence as the difference between the highest score and the score of the other classes summed, at a certain point.
@@ -321,4 +334,4 @@ Learn more about `px`, `go.Contour`, and `go.Heatmap` here:
321334
This tutorial was inspired by amazing examples from the official scikit-learn docs:
322335
* https://scikit-learn.org/stable/auto_examples/neighbors/plot_classification.html
323336
* https://scikit-learn.org/stable/auto_examples/classification/plot_classifier_comparison.html
324-
* https://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html
337+
* https://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html

Diff for: doc/python/ml-pca.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.1'
9-
jupytext_version: 1.1.1
8+
format_version: '1.2'
9+
jupytext_version: 1.6.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.7.6
2424
plotly:
2525
description: Visualize Principle Component Analysis (PCA) of your high-dimensional
2626
data in Python with Plotly.
@@ -136,6 +136,19 @@ fig.update_traces(diagonal_visible=False)
136136
fig.show()
137137
```
138138

139+
## PCA analysis in Dash
140+
141+
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash`, click "Download" to get the code and run `python app.py`.
142+
143+
Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with <a class="plotly-red" href="https://plotly.com/dash/">Dash Enterprise</a>.**
144+
145+
146+
```python hide_code=true
147+
from IPython.display import IFrame
148+
snippet_url = 'https://dash-gallery.plotly.host/python-docs-dash-snippets/'
149+
IFrame(snippet_url + 'pca-visualization', width='100%', height=630)
150+
```
151+
139152
## 2D PCA Scatter Plot
140153

141154
In the previous examples, you saw how to visualize high-dimensional PCs. In this example, we show you how to simply visualize the first two principal components of a PCA, by reducing a dataset of 4 dimensions to 2D.
@@ -262,4 +275,4 @@ The following resources offer an in-depth overview of PCA and explained variance
262275
* https://scikit-learn.org/stable/modules/decomposition.html#pca
263276
* https://stats.stackexchange.com/questions/2691/making-sense-of-principal-component-analysis-eigenvectors-eigenvalues/140579#140579
264277
* https://stats.stackexchange.com/questions/143905/loadings-vs-eigenvectors-in-pca-when-to-use-one-or-another
265-
* https://stats.stackexchange.com/questions/22569/pca-and-proportion-of-variance-explained
278+
* https://stats.stackexchange.com/questions/22569/pca-and-proportion-of-variance-explained

Diff for: doc/python/ml-roc-pr.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.1'
9-
jupytext_version: 1.1.1
8+
format_version: '1.2'
9+
jupytext_version: 1.6.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.7.6
2424
plotly:
2525
description: Interpret the results of your classification using Receiver Operating
2626
Characteristics (ROC) and Precision-Recall (PR) Curves in Python with Plotly.
@@ -119,6 +119,19 @@ fig.update_xaxes(constrain='domain')
119119
fig.show()
120120
```
121121

122+
## ROC curve in Dash
123+
124+
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash`, click "Download" to get the code and run `python app.py`.
125+
126+
Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with <a class="plotly-red" href="https://plotly.com/dash/">Dash Enterprise</a>.**
127+
128+
129+
```python hide_code=true
130+
from IPython.display import IFrame
131+
snippet_url = 'https://dash-gallery.plotly.host/python-docs-dash-snippets/'
132+
IFrame(snippet_url + 'roc-and-pr-curves', width='100%', height=630)
133+
```
134+
122135
## Multiclass ROC Curve
123136

124137
When you have more than 2 classes, you will need to plot the ROC curve for each class separately. Make sure that you use a [one-versus-rest](https://scikit-learn.org/stable/modules/multiclass.html#one-vs-the-rest) model, or make sure that your problem has a [multi-label](https://scikit-learn.org/stable/modules/multiclass.html#multilabel-classification-format) format; otherwise, your ROC curve might not return the expected results.

Diff for: doc/python/multiple-axes.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.4.2
9+
jupytext_version: 1.6.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.7.6
2424
plotly:
2525
description: How to make a graph with multiple axes (dual y-axis plots, plots
2626
with secondary axes) in python.
@@ -75,6 +75,19 @@ fig.update_yaxes(title_text="<b>secondary</b> yaxis title", secondary_y=True)
7575
fig.show()
7676
```
7777

78+
### Multiple axes in Dash
79+
80+
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash`, click "Download" to get the code and run `python app.py`.
81+
82+
Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with <a class="plotly-red" href="https://plotly.com/dash/">Dash Enterprise</a>.**
83+
84+
85+
```python hide_code=true
86+
from IPython.display import IFrame
87+
snippet_url = 'https://dash-gallery.plotly.host/python-docs-dash-snippets/'
88+
IFrame(snippet_url + 'multiple-axes', width='100%', height=630)
89+
```
90+
7891
#### Muliple Y-Axes Subplots
7992

8093
```python
@@ -233,4 +246,4 @@ fig.show()
233246
```
234247

235248
#### Reference
236-
All of the y-axis properties are found here: https://plotly.com/python/reference/YAxis/. For more information on creating subplots see the [Subplots in Python](/python/subplots/) section.
249+
All of the y-axis properties are found here: https://plotly.com/python/reference/YAxis/. For more information on creating subplots see the [Subplots in Python](/python/subplots/) section.

Diff for: doc/python/network-graphs.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.1'
9-
jupytext_version: 1.1.1
8+
format_version: '1.2'
9+
jupytext_version: 1.6.0
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.8
23+
version: 3.7.6
2424
plotly:
2525
description: How to make Network Graphs in Python with Plotly. One examples of
2626
a network graph with NetworkX
@@ -145,5 +145,18 @@ fig.show()
145145
```
146146

147147

148+
### Network graphs in Dash
149+
150+
[Dash](https://plotly.com/dash/) is the best way to build analytical apps in Python using Plotly figures. To run the app below, run `pip install dash dash-cytoscape`, click "Download" to get the code and run `python app.py`.
151+
152+
Get started with [the official Dash docs](https://dash.plotly.com/installation) and **learn how to effortlessly [style](https://plotly.com/dash/design-kit/) & [deploy](https://plotly.com/dash/app-manager/) apps like this with <a class="plotly-red" href="https://plotly.com/dash/">Dash Enterprise</a>.**
153+
154+
155+
```python hide_code=true
156+
from IPython.display import IFrame
157+
snippet_url = 'https://dash-gallery.plotly.host/python-docs-dash-snippets/'
158+
IFrame(snippet_url + 'network-graphs', width='100%', height=630)
159+
```
160+
148161
#### Reference
149-
See https://plotly.com/python/reference/scatter/ for more information and chart attribute options!
162+
See https://plotly.com/python/reference/scatter/ for more information and chart attribute options!

0 commit comments

Comments
 (0)