Plotly doesn't load most of the time

I ended up embedding the plotly code into a flask app. That works flawlessly. Thanks for your help!

Here’s an example if anyone wants to do the same:

app.py:

from flask import Flask, render_template
import plotly.figure_factory as ff
import plotly
import json

import numpy as np
import pandas as pd

app = Flask(__name__)

df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/minoritymajority.csv')
df_sample_r = df_sample[df_sample['STNAME'] == 'California']

values = df_sample_r['TOT_POP'].tolist()
fips = df_sample_r['FIPS'].tolist()

colorscale = [
    'rgb(193, 193, 193)',
    'rgb(239,239,239)',
    'rgb(195, 196, 222)',
    'rgb(144,148,194)',
    'rgb(101,104,168)',
    'rgb(65, 53, 132)'
]

fig = ff.create_choropleth(
    fips=fips, values=values, scope=['CA', 'AZ', 'Nevada', 'Oregon', ' Idaho'],
    binning_endpoints=[14348, 63983, 134827, 426762, 2081313], colorscale=colorscale,
    county_outline={'color': 'rgb(255,255,255)', 'width': 0.5}, round_legend_values=True,
    legend_title='Population by County', title='California and Nearby States'
)
fig.layout.template = None
graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)

@app.route("/")
def home():
    return render_template('index.html', v = graphJSON)

if __name__ == "__main__":
    app.run(debug = True)

templates/index.html:

<html>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<H2> A map with Folium </H2>
<p>A map example using the Folium library</p>
<div class="chart" id="bargraph">
    <script>
        var graphs = {{v | safe}};
        Plotly.plot('bargraph', graphs,{});
    </script>
</div>
<p>Attributing Stamen Terrain Maps</p>
</html>