Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Plotly in a WebView #8

@gerald-brandt

Description

@gerald-brandt

I've been trying to embed a plotly graph into a webview, but just get a blank display. Is this possible, or am I doing something wrong?

If I put the ploty html file behind a webserver, it works fine. I just can't load directly.

# flet run --web main.py

import flet as ft

import flet_webview as fwv

import plotly.express as px
import plotly.io as pio

def main(page: ft.Page):

    fig = px.scatter(x=range(10), y=range(10))
    pio.write_html(fig, file="file.html")

    html = open("file.html", "r").read()

    wv = fwv.WebView(
        url=f"data:text/html,{html}",
        on_page_started=lambda _: print("Page started"),
        on_page_ended=lambda _: print("Page ended"),
        on_web_resource_error=lambda e: print("Page error:", e.data),
        enable_javascript=True,
        on_javascript_alert_dialog=lambda e: print("Alert dialog:", e.data),
        expand=True,
    )
    page.add(wv)

    wv.can_go_forward = True
    wv.on_console_message=lambda e: print("Console message:", e.data)
    wv.on_web_resource_error=lambda e: print("Web resource error:", e.data)
    wv.update()

ft.app(main)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions