散点图不显示在QWebView中 [英] Bokeh plots do not display in QWebView

查看:214
本文介绍了散点图不显示在QWebView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可以在Linux和我的Windows 7机器上工作,即使使用 WinPython 环境:

 #plt_file是由Bokeh生成的有效html,并且在浏览器
中以open(plt_file,r)正确显示为f:
plot = f.read()
#self.plot_web_view.setContent(plot)$ b $ url url = QUrl(plt_file)
self.plot_web_view.setHtml(plot,url)

但是当我使用 WinPyhton 我的情节没有出现在 QWebView 中,并且没有错误发生......如果我尝试将随机html文件加载到 QWebView 在我的应用程序中显示。我猜这个问题是在 Qt 一边,但我不知道该怎么办...



PyQt 版本在 WinPython 是5.5.1

解决方案

Bokeh实际上是两个库:一个Python库Bokeh
和一个JavaScript库BokehJS。 JavaScript库BokehJS实际上是浏览器中的所有工作,并且是绝对必需的。一个小小的搜索引擎出现了很多链接,包括这个其他的StackOverflow答案,这似乎表明 QWebView 不会在HTML中加载外部< script> 标签。如果是这种情况,您将不得不寻找其他方法来加载所需的BokehJS文件。另一种选择可能是使用内联BokehJS,当您运行脚本创建HTML文件时,可以通过设置环境变量 BOKEH_RESOURCES = inline 来完成。请注意,这会使单个HTML输出文件更大(BokehJS是一个相当庞大的库),并且还会打败现代浏览器所做外部脚本的缓存(但也许 QWebView

最后,虽然我希望你能找到一个可行的路径,但要清楚: QWebView 不是受支持的平台,因为没有进行测试来确保Bokeh与 QWebView 兼容,并且不保证与<声明了code> QWebView 。

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

解决方案

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.

这篇关于散点图不显示在QWebView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆