From 62857a059de5685ea279ff60847715b971ba5a21 Mon Sep 17 00:00:00 2001 From: Rodja Trappe Date: Mon, 12 Jun 2023 05:53:50 +0200 Subject: [PATCH] extend fastapi example to use storage in run_with --- examples/fastapi/frontend.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/fastapi/frontend.py b/examples/fastapi/frontend.py index 2e653660f..4a7ac30ef 100644 --- a/examples/fastapi/frontend.py +++ b/examples/fastapi/frontend.py @@ -1,11 +1,18 @@ from fastapi import FastAPI -from nicegui import ui +from nicegui import app, ui -def init(app: FastAPI) -> None: +def init(fastapi_app: FastAPI) -> None: @ui.page('/show') def show(): ui.label('Hello, FastAPI!') - ui.run_with(app) + # 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='pick your private secret here' # NOTE setting a secret is optional but allows for persistent storage per user + )