Skip to content

Instantly share code, notes, and snippets.

@mtanco
Created June 4, 2024 16:02
Show Gist options
  • Save mtanco/c2c601b4fe42f484eab1982cf2c27ccd to your computer and use it in GitHub Desktop.
Save mtanco/c2c601b4fe42f484eab1982cf2c27ccd to your computer and use it in GitHub Desktop.
Wave long running task
from h2o_wave import main, app, Q, ui, on, handle_on
@app('/')
async def serve(q: Q):
# First time a browser comes to the app
if not q.client.initialized:
await init(q)
q.client.initialized = True
q.page["meta"].dialog = ui.dialog(
title="Please Wait!",
blocking=True,
items=[
ui.progress("")
]
)
await q.page.save() # Show everything so far to the User
await q.sleep(3) ## Wait 3 seconds
q.page["meta"].dialog = None # get rid of the waiting
# Other browser interactions
await handle_on(q)
await q.page.save()
async def init(q: Q) -> None:
q.client.dark_mode = False
q.page['meta'] = ui.meta_card(
box='',
title='My Wave App',
theme='light',
layouts=[
ui.layout(
breakpoint='xs',
min_height='100vh',
max_width='1200px',
zones=[
ui.zone('header'),
ui.zone('content', size='1', zones=[
ui.zone('horizontal', direction=ui.ZoneDirection.ROW),
ui.zone('vertical', size='1', ),
ui.zone('grid', direction=ui.ZoneDirection.ROW, wrap='stretch', justify='center')
]),
ui.zone(name='footer'),
]
)
]
)
q.page['header'] = ui.header_card(
box='header',
title='My Wave App',
subtitle="Example to get us started",
image='https://wave.h2o.ai/img/h2o-logo.svg',
)
q.page['footer'] = ui.footer_card(
box='footer',
caption='Made with 💛 using [H2O Wave](https://wave.h2o.ai).'
)
await home(q)
@on()
async def home(q: Q):
q.page["test"] = ui.form_card(box='vertical', items=[ui.text('This is my app!')])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment