0

As per the following SO article: How to display html using QWebView. Python?

I modified the following code by Andrean:

import sys
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebView

class Browser(QWebView):

    def __init__(self):
        QWebView.__init__(self)
        self.loadFinished.connect(self._result_available)

    def _result_available(self, ok):
        frame = self.page().mainFrame()
        # print(unicode(frame.toHtml()).encode('utf-8'))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    view = Browser()
    view.load(QUrl('http://www.google.com'))
    view.show()
    app.exec_()

However, for some strange reason, I still cannot view Google within my GUI window. I get the following screen below (despite waiting 5 minutes and having full internet connectivity)

See screenshot here

More importantly, I'm trying to view an offline HTML file which was generated using Bokeh.

from bokeh.plotting import figure, output_file, show

# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

# create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')

# add a line renderer with legend and line thickness
p.line(x, y, legend="Temp.", line_width=2)

# show the results
show(p)

Replacing the GUI script appropriately with the offline html file:

htmlPath = QUrl('line_example.html')
view.load(htmlPath)

I still cannot see the HTML file I've generated - showing the same blank window as before.

I've also tried defining htmlPath as below but they still don't work:

htmlPath = QUrl("file:///C:/Users/giranm/PycharmProjects/Dashboard%20Testing/lineGraph.html")

htmlPath = QUrl.fromLocalFile(QFileInfo("lineGraph.html").absoluteFilePath())

Any assistance to get the above working would be much appreciated.

Community
  • 1
  • 1
giran
  • 368
  • 1
  • 2
  • 11

1 Answers1

0

Please see this answer: Bokeh plots do not display in QWebView

TLDR: Evidently QWebView will not run <script> tags that are required to load BokehJS (which is the JavaScript library that actually does all the work to render things) Inline resources might be an option, though be aware that QwebView is not considered "supported" by Bokeh in any meaningful way.

Community
  • 1
  • 1
bigreddot
  • 33,642
  • 5
  • 69
  • 122