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: doc/python/interactive-html-export.md
+16-13
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,9 @@ jupyter:
6
6
extension: .md
7
7
format_name: markdown
8
8
format_version: '1.3'
9
-
jupytext_version: 1.14.1
9
+
jupytext_version: 1.14.6
10
10
kernelspec:
11
-
display_name: Python 3
11
+
display_name: Python 3 (ipykernel)
12
12
language: python
13
13
name: python3
14
14
language_info:
@@ -20,7 +20,7 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.8.8
23
+
version: 3.10.11
24
24
plotly:
25
25
description: Plotly allows you to save interactive HTML versions of your figures
26
26
to your local disk.
@@ -57,22 +57,25 @@ By default, the resulting HTML file is a fully self-contained HTML file which ca
57
57
58
58
### Inserting Plotly Output into HTML using a Jinja2 Template
59
59
60
-
You can insert Plotly output and text related to your data into HTML templates using Jinja2. Use `.to_html` to send the HTML to a Python string variable rather than using `write_html` to send the HTML to a disk file. Use the `full_html=False` option to output just the code necessary to add a figure to a template. We don't want to output a full HTML page, as the template will define the rest of the page's structure — for example, the page's `HTML` and `BODY` tags. First create an HTML template file containing a Jinja `{{ variable }}`. In this example, we customize the HTML in the template file by replacing the Jinja variable `{{ fig }}` with our graphic `fig`.
60
+
You can insert Plotly output and text related to your data into HTML templates using Jinja2. Use `.to_html` to send the HTML to a Python string variable rather than using `write_html` to send the HTML to a disk file. Use the `full_html=False` option to output just the code necessary to add a figure to a template. We don't want to output a full HTML page, as the template will define the rest of the page's structure — for example, the page's `HTML` and `BODY` tags. First create an HTML template file containing a Jinja `{{ variable }}`. In this example, we customize the HTML in the template file by replacing the Jinja variable `{{ fig }}` with our graphic `fig`.
61
+
62
+
<!-- #region -->
61
63
62
64
```
63
-
<!DOCTYPE html>
64
-
<html>
65
-
<body>
66
-
<h1>Here's a Plotly graph!</h1>
65
+
<!DOCTYPE html>
66
+
<html>
67
+
<body>
68
+
<h1>Here's a Plotly graph!</h1>
67
69
{{ fig }}
68
-
<p>And here's some text after the graph.</p>
69
-
</body>
70
-
</html>
70
+
<p>And here's some text after the graph.</p>
71
+
</body>
72
+
</html>
71
73
```
72
74
75
+
73
76
Then use the following Python to replace `{{ fig }}` in the template with HTML that will display the Plotly figure "fig":
74
77
75
-
```
78
+
```python
76
79
import plotly.express as px
77
80
from jinja2 import Template
78
81
@@ -90,7 +93,7 @@ with open(output_html_path, "w", encoding="utf-8") as output_file:
0 commit comments