Include_plotlyjs = 'cdn' not work

Hi all,
this is my code

import plotly as py
import pandas as pd
import numpy as np

from datetime import datetime
from datetime import time as dt_tm
from datetime import date as dt_date

# import plotly.plotly as py
import plotly.tools as plotly_tools
import plotly.graph_objs as go

import os
import tempfile
os.environ['MPLCONFIGDIR'] = tempfile.mkdtemp()
# from matplotlib.finance import quotes_historical_yahoo
import matplotlib.pyplot as plt

from scipy.stats import gaussian_kde

from IPython.display import HTML
import plotly.express as px

long_df = px.data.medals_long()

fig = px.bar(long_df, x="nation", y="count", color="medal", title="Long-Form Input")
import plotly.io as pio
def convert_fig_to_html(fig):
    pio.write_html(fig,'file.html',full_html=False,include_plotlyjs='cdn')
    html=open("file.html", "r")
    html=html.read()
    return html
html_string = '''
<html>
    <head>
        
        <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> 
    
    </head>
    <body>
        
        <h3>Reference table: stock tickers</h3>
        ''' + convert_fig_to_html(fig) + '''
        <h3>Summary table: 2014 stock statistics</h3>
        ''' + convert_fig_to_html(fig) + '''
    </body>
</html>'''

f = open('report.html','w')
f.write(html_string)
f.close()

When I open html file, it not show charts. It have error:

if I use include_plotlyjs =β€˜False’, it will show chart, but the file size too large.
Are there any solution for this problems?
Thanks

Plotly had some trouble with their data behind the CDNs; see: Plotly.js CDN down?

This seems to be fixed, so you can try again!

1 Like