Created
October 23, 2019 08:49
-
-
Save macleginn/5ef6dce81f3fd6a8b74a5ee655e2393b to your computer and use it in GitHub Desktop.
An example of an offline Plotly plot created using Python with Plotly.js included once in the <head> section of the page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly.express as px | |
import plotly.offline | |
template = """ | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
<script>{plotly}</script> | |
</head> | |
<body> | |
{plot} | |
</body> | |
</html> | |
""" | |
fig = px.histogram(px.data.tips(),x="total_bill") | |
fig_div = fig.to_html(include_plotlyjs=False) | |
## Works in the same way: | |
# fig_div = plotly.offline.plot(fig, | |
# output_type='div', | |
# include_plotlyjs=False) | |
result = template.format( | |
plotly=plotly.offline.get_plotlyjs(), | |
plot=fig_div | |
) | |
with open('test.html', 'w') as out: | |
out.write(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment