open plotly in qwebview in interactive mode

前端 未结 1 1216
轮回少年
轮回少年 2020-12-18 15:11

I\'m using plotly library in offline mode with python and what I\'m trying to do is to create some plot, save them as local html and load in a second moment int

相关标签:
1条回答
  • 2020-12-18 15:41

    Ok, I should have find what the problem is.

    Is seems that QWebView has some difficulties to load the local file because it is too heavy (about 2mb for simple plot).

    So I used the option to not include the javascript when saving the local file and to load the javascript in a second moment thanks, as described here.

    In other words, create the initial html tags, include the result of the figure generated by plotly without the whole javascript code, and include the link of the javascript.

    In this way the file is super light and QWebView does not have issue to open it.

    # create the initial html code
    raw_html = '<head><meta charset="utf-8" /></head>''<head><meta charset="utf-8" /><script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head>'
    
    # call the plot method without all the javascript code
    raw_html += plotly.offline.plot(fig, filename = fn, include_plotlyjs=False)
    
    # close the body and html tags
    raw_html += '</body></html>'
    
    0 讨论(0)
提交回复
热议问题