Bokeh plots do not display in QWebView

点点圈 提交于 2019-12-01 10:00:21

问题


I have following code that works on linux and my windows 7 machine even using WinPython environment:

   # plt_file is valid html produced by Bokeh and that is correctly displayed in browser
   with open(plt_file, "r") as f:
            plot = f.read()
            # self.plot_web_view.setContent(plot)
            url = QUrl(plt_file)
            self.plot_web_view.setHtml(plot, url)

But when I distribute my application using WinPyhton my plot doesn't show up in QWebView and no error is raised... If I try to load random html-files into QWebView in my app they are displayed. I guess the issue is on Qt side, but I have no clue what to do...

PyQt version in WinPython is 5.5.1


回答1:


Bokeh is actually two libraries: a Python library "Bokeh ", and a JavaScript library "BokehJS". The JavaScript library BokehJS is actually what does all the work in the browser, and is absolutely required. A little googling turns up many links, including this other StackOverflow answer, which seem to indicated that QWebView does not load external <script> tags in HTML. If that is the case, you will have to find some other means to load the required BokehJS files. Another option might be to use "inline" BokehJS, which can be accomplished by one way by setting the environment variable BOKEH_RESOURCES=inline when you run the scripts to create the HTML files. Please be aware that this will make individual HTML output files substantially larger (BokehJS is a fairly hefty library) and additionally will defeat any caching of external scripts that modern browsers do (but maybe QWebView doesn't do that anyway).

Lastly, while I do hope you can find a path that works, just to be clear: QWebView is not a "supported" platform, in the sense that no testing is done to ensure Bokeh is compatible with QWebView and no guarantee of compatibility with QWebView is claimed.




回答2:


would this work better ?

   plot = ""
   with open(plt_file, "r") as f:
        plot = f.read()
   # self.plot_web_view.setContent(plot)
   url = QUrl(plt_file)
   self.plot_web_view.setHtml(plot, url)


来源:https://stackoverflow.com/questions/39560342/bokeh-plots-do-not-display-in-qwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!