QWebEngineView renders bokeh vizualisation with largish data (~18000 points) slowly

I’m trying to include a Bokeh based visualisation canvas in a Qt application written in Python (using PySide6). So I create the visualisation, save it in an HTML file, and read it in a QWebEngineView widget. It renders fine, but is extremely sluggish to interact with it; e.g. try selecting the zoom tool and zooming in, or panning. The surprising part is, when I open the same HTML in Firefox, it is pretty snappy, as I would expect.

There are 2 time series, with 8760 data points each in the plot. What is going on here?

Minimal example

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>from argparse import ArgumentParser
from pathlib import Path
from PySide6.QtCore import QUrl, QSize
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtWebEngineWidgets import QWebEngineView
class MainWindow(QMainWindow):
def __init__(self, path: str = "", *args, **kwargs):
super().__init__(*args, **kwargs)
if path:
self.browser = QWebEngineView()
self.browser.setUrl(QUrl.fromLocalFile(Path(path).absolute()))
self.setCentralWidget(self.browser)
self.resize(QSize(800, 500))
if __name__ == "__main__":
# HTML example produced using Bokeh: dump-viz.html
parser = ArgumentParser()
parser.add_argument("file")
opts = parser.parse_args()
app = QApplication()
window = MainWindow(opts.file)
window.show()
app.exec()
</code>
<code>from argparse import ArgumentParser from pathlib import Path from PySide6.QtCore import QUrl, QSize from PySide6.QtWidgets import QApplication, QMainWindow from PySide6.QtWebEngineWidgets import QWebEngineView class MainWindow(QMainWindow): def __init__(self, path: str = "", *args, **kwargs): super().__init__(*args, **kwargs) if path: self.browser = QWebEngineView() self.browser.setUrl(QUrl.fromLocalFile(Path(path).absolute())) self.setCentralWidget(self.browser) self.resize(QSize(800, 500)) if __name__ == "__main__": # HTML example produced using Bokeh: dump-viz.html parser = ArgumentParser() parser.add_argument("file") opts = parser.parse_args() app = QApplication() window = MainWindow(opts.file) window.show() app.exec() </code>
from argparse import ArgumentParser
from pathlib import Path


from PySide6.QtCore import QUrl, QSize
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtWebEngineWidgets import QWebEngineView


class MainWindow(QMainWindow):
    def __init__(self, path: str = "", *args, **kwargs):
        super().__init__(*args, **kwargs)

        if path:
            self.browser = QWebEngineView()
            self.browser.setUrl(QUrl.fromLocalFile(Path(path).absolute()))
            self.setCentralWidget(self.browser)
            self.resize(QSize(800, 500))


if __name__ == "__main__":
    # HTML example produced using Bokeh: dump-viz.html
    parser = ArgumentParser()
    parser.add_argument("file")
    opts = parser.parse_args()

    app = QApplication()
    window = MainWindow(opts.file)
    window.show()
    app.exec()

The above script, and an example HTML is available in this gist.

You can run it with hatch run pyside-qwebengine-slow.py qwebengine-ex-viz.html, or create a virtual env, then pip install PySide6, and run normally.

Additional info

The code that I use to generate that plot, is more or less equivalent to:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def make_plot(data_list)
"""`data_list`: list of dataclasses representing a time series;
data.y, data.labels, etc.
"""
palette = TolRainbow[10]
legend_items = {}
fig = figure(x_axis_label="x_label", y_axis_label="y_label", title="title", height=400, width=800)
for idx, data in enumerate(data_list):
df = pd.DataFrame({y_label: data.y})
line = fig.line("index", "y_label", source=df, color=palette[idx])
point = fig.scatter("index", "y_label", source=df, color=palette[idx], size=7)
legend_items[data.labels[0]] = [line, point]
legend = Legend(items=list(legend_items.items()))
fig.add_layout(legend, "right")
fig.legend.click_policy = "hide"
return fig
fig = make_plot(data_list)
html = file_html(fig, INLINE, title)
</code>
<code>def make_plot(data_list) """`data_list`: list of dataclasses representing a time series; data.y, data.labels, etc. """ palette = TolRainbow[10] legend_items = {} fig = figure(x_axis_label="x_label", y_axis_label="y_label", title="title", height=400, width=800) for idx, data in enumerate(data_list): df = pd.DataFrame({y_label: data.y}) line = fig.line("index", "y_label", source=df, color=palette[idx]) point = fig.scatter("index", "y_label", source=df, color=palette[idx], size=7) legend_items[data.labels[0]] = [line, point] legend = Legend(items=list(legend_items.items())) fig.add_layout(legend, "right") fig.legend.click_policy = "hide" return fig fig = make_plot(data_list) html = file_html(fig, INLINE, title) </code>
def make_plot(data_list)
    """`data_list`: list of dataclasses representing a time series;
    data.y, data.labels, etc.
    """
    palette = TolRainbow[10]
    legend_items = {}
    fig = figure(x_axis_label="x_label", y_axis_label="y_label", title="title", height=400, width=800)
    for idx, data in enumerate(data_list):
        df = pd.DataFrame({y_label: data.y})
        line = fig.line("index", "y_label", source=df, color=palette[idx])
        point = fig.scatter("index", "y_label", source=df, color=palette[idx], size=7)
        legend_items[data.labels[0]] = [line, point]

    legend = Legend(items=list(legend_items.items()))
    fig.add_layout(legend, "right")
    fig.legend.click_policy = "hide"
    return fig

fig = make_plot(data_list)
html = file_html(fig, INLINE, title)

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật