Skip to content

Commit 4001477

Browse files
authored
Merge pull request #4479 from plotly/fix-page
Fix rendering issues on page
2 parents e285e63 + cf7c5a8 commit 4001477

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

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

+16-13
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.14.6
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.8
23+
version: 3.10.11
2424
plotly:
2525
description: Plotly allows you to save interactive HTML versions of your figures
2626
to your local disk.
@@ -57,22 +57,25 @@ By default, the resulting HTML file is a fully self-contained HTML file which ca
5757

5858
### Inserting Plotly Output into HTML using a Jinja2 Template
5959

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 -->
6163

6264
```
63-
<!DOCTYPE html>
64-
<html>
65-
<body>
66-
<h1>Here's a Plotly graph!</h1>
65+
&lt;!DOCTYPE html&gt;
66+
&lt;html&gt;
67+
&lt;body&gt;
68+
&lt;h1&gt;Here's a Plotly graph!&lt;/h1&gt;
6769
{{ fig }}
68-
<p>And here's some text after the graph.</p>
69-
</body>
70-
</html>
70+
&lt;p&gt;And here's some text after the graph.&lt;/p&gt;
71+
&lt;/body&gt;
72+
&lt;/html&gt;
7173
```
7274

75+
7376
Then use the following Python to replace `{{ fig }}` in the template with HTML that will display the Plotly figure "fig":
7477

75-
```
78+
```python
7679
import plotly.express as px
7780
from jinja2 import Template
7881

@@ -90,7 +93,7 @@ with open(output_html_path, "w", encoding="utf-8") as output_file:
9093
j2_template = Template(template_file.read())
9194
output_file.write(j2_template.render(plotly_jinja_data))
9295
```
93-
96+
<!-- #endregion -->
9497

9598
### HTML export in Dash
9699

0 commit comments

Comments
 (0)