zauberzeug / nicegui

Create web-based user interfaces with Python. The nice way.
https://nicegui.io
MIT License
10.16k stars 605 forks source link

Plotly not available in native window #3928

Closed da-i closed 1 week ago

da-i commented 3 weeks ago

Description

Using Ubuntu 24.04.1 LTS i tried to run a native test with the plotly update example, but got an error:

test.py:

import plotly.graph_objects as go
from nicegui import ui, native
from random import random

fig = go.Figure()
fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
plot = ui.plotly(fig).classes('w-full h-40')

def add_trace(fig,plot):
    fig.add_trace(go.Scatter(x=[1, 2, 3], y=[random(), random(), random()]))
    plot.update()

ui.button('Add trace', on_click= lambda: add_trace(fig,plot))

ui.run(
    favicon="🚀",
    title="Test plot",
    native=True,
    reload=False,
    port=native.find_open_port(),
    window_size=(1600, 1200),
    storage_secret="somesecret",
)

Setup simple env for test

>conda create -n UI_test3 -c conda-forge python=3.11
>conda activate UI_test3
>pip install "nicegui[plotly]"
Collecting nicegui[plotly]
  Downloading nicegui-2.5.0-py3-none-any.whl.metadata (10 kB)
.....
>pip install "pywebview[qt]"
....

When i run the example

> python test.py
NiceGUI ready to go on http://localhost:8000
[pywebview] GTK cannot be loaded
Traceback (most recent call last):
  File "/home/dami/anaconda3/envs/UI_test3/lib/python3.11/site-packages/webview/guilib.py", line 37, in import_gtk
    import webview.platforms.gtk as guilib
  File "/home/dami/anaconda3/envs/UI_test3/lib/python3.11/site-packages/webview/platforms/gtk.py", line 20, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'
js: TypeError: Failed to resolve module specifier 'plotly'

Is this a known issue? I could not find much detail in the docs about this.

rodja commented 3 weeks ago

Does the same happen in a plain pywebview application without NiceGUI?

falkoschindler commented 1 week ago

Without further information, there's not much we can do here. I'll close this issue for now.