Skip to content

Commit 4d8baf4

Browse files
Update interactive-html-export.md based on Plotly comments
1 parent 8cdc5ab commit 4d8baf4

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,20 @@ 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. First create an HTML template file containing a variable like `{{ fig }}`. Then use the following Python to replace `{{ fig }}` in the template with HTML that will display the Plotly figure "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 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 that will provide e.g. the `<HTML>` tag rather than asking Plotly to ouput a complete webpage. 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+
```
63+
<!DOCTYPE html>
64+
<html>
65+
<body>
66+
<h1>Here's a Plotly graph!</h1>
67+
{{ fig }}
68+
<p>And here's some text after the graph.</p>
69+
</body>
70+
</html>
71+
```
72+
73+
Then use the following Python to replace `{{ fig }}` in the template with HTML that will display the Plotly figure "fig":
6174

6275
```
6376
import plotly.express as px

0 commit comments

Comments
 (0)