Skip to content

Commit

Permalink
extend fastapi example to use storage in run_with
Browse files Browse the repository at this point in the history
  • Loading branch information
rodja committed Jun 12, 2023
1 parent bc1d174 commit 62857a0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions examples/fastapi/frontend.py
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 62857a0

Please sign in to comment.