question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Embedd offline plots in PyQt WebView (python)

See original GitHub issue

Hi all, It seems that there are some troubles when embedding an offline plot in a QWebView. Here the code http://pastebin.com/MSKnCExp

  1. if directly loading the plot in a QWebView then the plot is not visible at all:

browser_001

  1. if the plot is opened in a default browser and then saved as html file from the browser, then the plot can be loaded and it is visible in the QWebView but no interactions are possible:

browser_002

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
jonmmeasecommented, Sep 22, 2018

In case anyone here is still interested, here’s a quick proof-of-concept of how to display a plotly figure in a pyqt5 context. This uses QWebEngineView, which is a full chromium based browser and it seems to support everything plotly.js needs (including WebGL).

import plotly.offline as po
import plotly.graph_objs as go

from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5 import QtCore, QtWidgets
import sys


def show_qt(fig):
    raw_html = '<html><head><meta charset="utf-8" />'
    raw_html += '<script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head>'
    raw_html += '<body>'
    raw_html += po.plot(fig, include_plotlyjs=False, output_type='div')
    raw_html += '</body></html>'

    fig_view = QWebEngineView()
    # setHtml has a 2MB size limit, need to switch to setUrl on tmp file
    # for large figures.
    fig_view.setHtml(raw_html)
    fig_view.show()
    fig_view.raise_()
    return fig_view


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)

    fig = go.Figure(data=[{'type': 'scattergl', 'y': [2, 1, 3, 1]}])
    fig_view = show_qt(fig)
    sys.exit(app.exec_())

0reactions
jonmmeasecommented, Sep 22, 2018

Yeah, as I understand it QWebEngineView is a bear to package. I installed Qt/pyqt using conda on OS X and it was included. I believe the same would be true when using conda on Linux. Not sure about windows though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I embed plotly graphs (offline) in my PyQt4 application?
PyQtgraph or MatPlotLib may be an option for you if you really need to embedd graphs in PyQT. Here's sample code to export...
Read more >
How can I embed plotly graphs (offline) in my PyQt application?
I want to embed plotly python graph in my PyQt application for working in desktop UI. Is there any way? Thanks in advance....
Read more >
Open Plotly In Qwebview In Interactive Mode - ADocLib
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...
Read more >
Matplotlib plots in PyQt5, embedding charts in ... - Python GUIs
In this tutorial we'll cover how to embed Matplotlib plots in your PyQt applications. Many other Python libraries — such as seaborn and ......
Read more >
5 Python GUI Frameworks to Create Desktop, Web, and Even ...
With it, you can create Desktop applications for Windows, OS X, and Linux, build mobile apps for iOS and Android, and use it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found