title: Embedding a Plotly chart in a Django template
body: <p>I am trying to embed a plotly pie chart in a Django html template. This works fine when the chart is produced in 'online mode' (i.e. the html snippet is stored on the plotly server) but not in 'offline mode' (i.e. when the html is stored locally). In the latter case, the chart does not appear. I want to be able to store the html on my local server and embed the plots from there.</p>
  
  <p>Here is the bit that works:</p>
  
  <pre><code>import plotly.plotly as py
  import plotly.graph_objs as go
  labels = [1,2,3,4]
  values = [10,20,30,40]
  ndata = 100
  fig = {
      'data': [{'labels': labels,
            'values': values,
            'type': 'pie',
            'textposition':"none",
            'textinfo':"percent",
            'textfont':{'size':'12'},
            'showlegend':'false'}],
      'layout': {'title': 'Total:'+str(ndata),
             'showlegend':'false',
             'height':'200',
             'width':'200',
             'autosize':'false',
             'margin':{'t':'50','l':'75','r':'0','b':'10'},
             'separators':'.,'}
  }
  plotly_url = py.plot(fig, filename='myfile', auto_open=False)
  pie_url = '&lt;iframe width="200" height="200" frameborder="0" seamless="seamless" scrolling="no" src='+plotly_url+'.embed?width=200&amp;height=200&amp;link=false&amp;showlegend=false&gt;&lt;/iframe&gt;'
  </code></pre>
  
  <p>Note that <strong>pie_url</strong> is passed as a string in the Http render request in Django. The template interprets the string as html using the <strong>|</strong> safe tag, i.e. {{ pie_url|safe }}.</p>
  
  <p>Here is the bit that doesn't work:</p>
  
  <pre><code>from plotly.offline import download_plotlyjs, plot
  import plotly.graph_objs as go
  labels = [1,2,3,4]
  values = [10,20,30,40]
  ndata = 100
  fig = {
      'data': [{'labels': labels,
            'values': values,
            'type': 'pie',
            'textposition':"none",
            'textinfo':"percent",
            'textfont':{'size':'12'},
            'showlegend':'false'}],
      'layout': {'title': 'Total:'+str(ndata),
             'showlegend':'false',
             'height':'200',
             'width':'200',
             'autosize':'false',
             'margin':{'t':'50','l':'75','r':'0','b':'10'},
             'separators':'.,'}
  }
  plotly_url = plot(fig, filename='file:///home/website/pie.html', auto_open=False)
  pie_url = '''&lt;iframe width="200" height="200" frameborder="0" seamless="seamless" scrolling="no" src=\"'''+plotly_url+'''.embed?width=200&amp;height=200&amp;link=false&amp;showlegend=false\"&gt;&lt;/iframe&gt;'''
  </code></pre>
  
  <p>Any advice would be appreciated.</p>