generated from Templates/Docker_Image
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Frontend module for NiceGUI with FastAPI integration.
|
|
|
|
This module provides the NiceGUI frontend that can be initialized with a FastAPI app.
|
|
The dashboard shown is from dashboard_ui.py with real-time database data.
|
|
"""
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from nicegui import app, ui
|
|
from dashboard_ui import create_dashboard
|
|
|
|
|
|
def init(fastapi_app: FastAPI, storage_secret: str = 'Secr2t!') -> None:
|
|
"""Initialize the NiceGUI frontend with the FastAPI app.
|
|
|
|
Args:
|
|
fastapi_app: The FastAPI application instance.
|
|
storage_secret: Optional secret for persistent user storage.
|
|
"""
|
|
|
|
@ui.page('/show')
|
|
def show():
|
|
create_dashboard()
|
|
|
|
# NOTE dark mode will be persistent for each user across tabs and server restarts
|
|
ui.dark_mode().bind_value(app.storage.user, 'dark_mode')
|
|
ui.checkbox('dark mode').bind_value(app.storage.user, 'dark_mode')
|
|
|
|
ui.run_with(
|
|
fastapi_app,
|
|
storage_secret=storage_secret, # NOTE setting a secret is optional but allows for persistent storage per user
|
|
) |