Python Plotly - Offline chart embed into HTML (Not working)
我已经建立了一个图表,想要嵌入到HTML文件中。 如果我在线使用
这是我的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | fig = dict(data=data, layout=layout) plotly.tools.set_credentials_file(username='*****', api_key='*****') aPlot = plotly.offline.plot(fig, config={"displayModeBar": False}, show_link=False, filename='pandas-continuous-error-bars.html') html_string = ''' <html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> <style>body{ margin:0 100; background:whitesmoke; }</style> </head> <body> Monthly Report <!-- *** Section 1 *** ---> <iframe width="1000" height="550" frameborder="0" seamless="seamless" scrolling="no" \\ src="''' + aPlot + '''.embed?width=800&height=550"></iframe> <p> (Insights). </p> </body> </html>''' f = open("C:/Users/nicholas\\Desktop/nick.html",'w') f.write(html_string) f.close() |
有谁知道为什么不嵌入以及如何修复它?
在
当您删除此字符串(即
除了嵌入整个HTML文件之外,您还可以使用此处建议的方法,该方法将生成一个较小的HTML文件,即,生成包含所有相关信息的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import plotly fig = {'data': [{'x': [1,2,3], 'y': [2,5,3], 'type': 'bar'}], 'layout': {'width': 800, 'height': 550}} aPlot = plotly.offline.plot(fig, config={"displayModeBar": False}, show_link=False, include_plotlyjs=False, output_type='div') html_string = ''' <html> <head> <script src="https://cdn.plot.ly/plotly-latest.min.js"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> <style>body{ margin:0 100; background:whitesmoke; }</style> </head> <body> Monthly Report ''' + aPlot + ''' </body> </html>''' with open("nick.html", 'w') as f: f.write(html_string) |