{ "Base Wave app": { "prefix": "w_app_base", "body": [ "from h2o_wave import main, app, Q, ui", "", "", "@app('/$1')", "async def serve(q: Q):", " $0", " await q.page.save()", "" ], "description": "Basic scaffolding for a wave app." }, "Wave client initialization": { "prefix": "w_init_client", "body": [ "if not q.client.initialized:", " $0", " q.client.initialized = True" ], "description": "Client level initialization logic." }, "Wave app initialization": { "prefix": "w_init_app", "body": [ "if not q.app.initialized:", " $0", " q.app.initialized = True" ], "description": "App-level initialization logic." }, "Wave user initialization": { "prefix": "w_init_user", "body": [ "if not q.user.initialized:", " $0", " q.user.initialized = True" ], "description": "User level initialization logic." }, "Base Wave script": { "prefix": "w_script_base", "body": [ "from h2o_wave import site, ui", "", "page = site['/$1']", "$0", "page.save()" ], "description": "Basic scaffolding for a wave script." }, "Wave page": { "prefix": "w_page", "body": [ "q.page['$1'] = $0" ], "description": "Creates a new page for a card." }, "Drop Wave page": { "prefix": "w_page_drop", "body": [ "q.page.drop()$0" ], "description": "Deletes all Wave cards." }, "Wave site upload": { "prefix": "w_site_upload", "body": [ "q.app.file1,$0 = await q.site.upload([${1}])" ], "description": "Uploads static files to Wave server" }, "Wave meta page": { "prefix": "w_meta", "body": [ "q.page['meta']$0" ], "description": "Shorthand for accessing meta card." }, "Wave on handler": { "prefix": "w_on", "body": [ "@on()", "async def $1(q: Q):", " $0" ], "description": "Wave interactivity handler." }, "Wave on route handler": { "prefix": "w_on_route", "body": [ "@on(arg='#$1')", "async def handle_$1(q: Q):", " $0", " await q.page.save()", "" ], "description": "Wave route handler." }, "Wave on route param handler": { "prefix": "w_on_route_param", "body": [ "@on(arg='#$1/{$2}')", "async def handle_$1(q: Q, $2: str):", " $0", " await q.page.save()", "" ], "description": "Wave route handler with URL param." }, "Wave page delete": { "prefix": "w_page_delete", "body": [ "del q.page['$1']$0" ], "description": "Delete a specific Wave card." }, "Wave app template with a header": { "prefix": "w_app_header", "body": [ "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", "", " # Other browser interactions", " await handle_on(q)", " await q.page.save()", "", "", "async def init(q: Q) -> None:", " q.client.cards = set()", " 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',", " items=[ui.menu(icon='', items=[ui.command(name='change_theme', icon='ClearNight', label='Dark Mode')])]", " )", " 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):", " clear_cards(q)", " add_card(q, 'form', ui.form_card(box='vertical', items=[ui.text('This is my app!')]))", "", "", "@on()", "async def change_theme(q: Q):", " \"\"\"Change the app from light to dark mode\"\"\"", " if q.client.dark_mode:", " q.page[\"header\"].items = [ui.menu([ui.command(name='change_theme', icon='ClearNight', label='Dark mode')])]", " q.page[\"meta\"].theme = \"light\"", " q.client.dark_mode = False", " else:", " q.page[\"header\"].items = [ui.menu([ui.command(name='change_theme', icon='Sunny', label='Light mode')])]", " q.page[\"meta\"].theme = \"h2o-dark\"", " q.client.dark_mode = True", "", "", "# Use for cards that should be deleted on calling `clear_cards`. Useful for routing and page updates.", "def add_card(q, name, card) -> None:", " q.client.cards.add(name)", " q.page[name] = card", "", "", "def clear_cards(q, ignore=[]) -> None:", " for name in q.client.cards.copy():", " if name not in ignore:", " del q.page[name]", " q.client.cards.remove(name)", "" ], "description": "A simple app with a header and a body." }, "Wave app template with sidebar": { "prefix": "w_app_sidebar_nav", "body": [ "from h2o_wave import main, app, Q, ui, on, handle_on, data", "from typing import Optional, List", "", "", "# Use for page cards that should be removed when navigating away.", "# For pages that should be always present on screen use q.page[key] = ...", "def add_card(q, name, card) -> None:", " q.client.cards.add(name)", " q.page[name] = card", "", "", "# Remove all the cards related to navigation.", "def clear_cards(q, ignore: Optional[List[str]] = []) -> None:", " if not q.client.cards:", " return", "", " for name in q.client.cards.copy():", " if name not in ignore:", " del q.page[name]", " q.client.cards.remove(name)", "", "", "@on('#page1')", "async def page1(q: Q):", " q.page['sidebar'].value = '#page1'", " clear_cards(q) # When routing, drop all the cards except of the main ones (header, sidebar, meta).", "", " for i in range(3):", " add_card(q, f'info{i}', ui.tall_info_card(box='horizontal', name='', title='Speed',", " caption='The models are performant thanks to...', icon='SpeedHigh'))", " add_card(q, 'article', ui.tall_article_preview_card(", " box=ui.box('vertical', height='600px'), title='How does magic work',", " image='https://images.pexels.com/photos/624015/pexels-photo-624015.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1',", " content='''", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac sodales felis. Duis orci enim, iaculis at augue vel, mattis imperdiet ligula. Sed a placerat lacus, vitae viverra ante. Duis laoreet purus sit amet orci lacinia, non facilisis ipsum venenatis. Duis bibendum malesuada urna. Praesent vehicula tempor volutpat. In sem augue, blandit a tempus sit amet, tristique vehicula nisl. Duis molestie vel nisl a blandit. Nunc mollis ullamcorper elementum.", "Donec in erat augue. Nullam mollis ligula nec massa semper, laoreet pellentesque nulla ullamcorper. In ante ex, tristique et mollis id, facilisis non metus. Aliquam neque eros, semper id finibus eu, pellentesque ac magna. Aliquam convallis eros ut erat mollis, sit amet scelerisque ex pretium. Nulla sodales lacus a tellus molestie blandit. Praesent molestie elit viverra, congue purus vel, cursus sem. Donec malesuada libero ut nulla bibendum, in condimentum massa pretium. Aliquam erat volutpat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer vel tincidunt purus, congue suscipit neque. Fusce eget lacus nibh. Sed vestibulum neque id erat accumsan, a faucibus leo malesuada. Curabitur varius ligula a velit aliquet tincidunt. Donec vehicula ligula sit amet nunc tempus, non fermentum odio rhoncus.", "Vestibulum condimentum consectetur aliquet. Phasellus mollis at nulla vel blandit. Praesent at ligula nulla. Curabitur enim tellus, congue id tempor at, malesuada sed augue. Nulla in justo in libero condimentum euismod. Integer aliquet, velit id convallis maximus, nisl dui porta velit, et pellentesque ligula lorem non nunc. Sed tincidunt purus non elit ultrices egestas quis eu mauris. Sed molestie vulputate enim, a vehicula nibh pulvinar sit amet. Nullam auctor sapien est, et aliquet dui congue ornare. Donec pulvinar scelerisque justo, nec scelerisque velit maximus eget. Ut ac lectus velit. Pellentesque bibendum ex sit amet cursus commodo. Fusce congue metus at elementum ultricies. Suspendisse non rhoncus risus. In hac habitasse platea dictumst.", " '''", " ))", "", "", "@on('#page2')", "async def page2(q: Q):", " q.page['sidebar'].value = '#page2'", " clear_cards(q) # When routing, drop all the cards except of the main ones (header, sidebar, meta).", " add_card(q, 'chart1', ui.plot_card(", " box='horizontal',", " title='Chart 1',", " data=data('category country product price', 10, rows=[", " ('G1', 'USA', 'P1', 124),", " ('G1', 'China', 'P2', 580),", " ('G1', 'USA', 'P3', 528),", " ('G1', 'China', 'P1', 361),", " ('G1', 'USA', 'P2', 228),", " ('G2', 'China', 'P3', 418),", " ('G2', 'USA', 'P1', 824),", " ('G2', 'China', 'P2', 539),", " ('G2', 'USA', 'P3', 712),", " ('G2', 'USA', 'P1', 213),", " ]),", " plot=ui.plot([ui.mark(type='interval', x='=product', y='=price', color='=country', stack='auto',", " dodge='=category', y_min=0)])", " ))", " add_card(q, 'chart2', ui.plot_card(", " box='horizontal',", " title='Chart 2',", " data=data('date price', 10, rows=[", " ('2020-03-20', 124),", " ('2020-05-18', 580),", " ('2020-08-24', 528),", " ('2020-02-12', 361),", " ('2020-03-11', 228),", " ('2020-09-26', 418),", " ('2020-11-12', 824),", " ('2020-12-21', 539),", " ('2020-03-18', 712),", " ('2020-07-11', 213),", " ]),", " plot=ui.plot([ui.mark(type='line', x_scale='time', x='=date', y='=price', y_min=0)])", " ))", " add_card(q, 'table', ui.form_card(box='vertical', items=[ui.table(", " name='table',", " downloadable=True,", " resettable=True,", " groupable=True,", " columns=[", " ui.table_column(name='text', label='Process', searchable=True),", " ui.table_column(name='tag', label='Status', filterable=True, cell_type=ui.tag_table_cell_type(", " name='tags',", " tags=[", " ui.tag(label='FAIL', color='\\$red'),", " ui.tag(label='DONE', color='#D2E3F8', label_color='#053975'),", " ui.tag(label='SUCCESS', color='\\$mint'),", " ]", " ))", " ],", " rows=[", " ui.table_row(name='row1', cells=['Process 1', 'FAIL']),", " ui.table_row(name='row2', cells=['Process 2', 'SUCCESS,DONE']),", " ui.table_row(name='row3', cells=['Process 3', 'DONE']),", " ui.table_row(name='row4', cells=['Process 4', 'FAIL']),", " ui.table_row(name='row5', cells=['Process 5', 'SUCCESS,DONE']),", " ui.table_row(name='row6', cells=['Process 6', 'DONE']),", " ])", " ]))", "", "", "@on('#page3')", "async def page3(q: Q):", " q.page['sidebar'].value = '#page3'", " clear_cards(q) # When routing, drop all the cards except of the main ones (header, sidebar, meta).", "", " for i in range(12):", " add_card(q, f'item{i}', ui.wide_info_card(box=ui.box('grid', width='400px'), name='', title='Tile',", " caption='Lorem ipsum dolor sit amet'))", "", "", "@on('#page4')", "async def handle_page4(q: Q):", " q.page['sidebar'].value = '#page4'", " # When routing, drop all the cards except of the main ones (header, sidebar, meta).", " # Since this page is interactive, we want to update its card instead of recreating it every time, so ignore 'form' card on drop.", " clear_cards(q, ['form'])", "", " if q.args.step1:", " # Just update the existing card, do not recreate.", " q.page['form'].items = [", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1'),", " ui.step(label='Step 2'),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox2', label='Textbox 1'),", " ui.buttons(justify='end', items=[", " ui.button(name='step2', label='Next', primary=True),", " ])", " ]", " elif q.args.step2:", " # Just update the existing card, do not recreate.", " q.page['form'].items = [", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1', done=True),", " ui.step(label='Step 2'),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox2', label='Textbox 2'),", " ui.buttons(justify='end', items=[", " ui.button(name='step1', label='Cancel'),", " ui.button(name='step3', label='Next', primary=True),", " ])", " ]", " elif q.args.step3:", " # Just update the existing card, do not recreate.", " q.page['form'].items = [", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1', done=True),", " ui.step(label='Step 2', done=True),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox3', label='Textbox 3'),", " ui.buttons(justify='end', items=[", " ui.button(name='step2', label='Cancel'),", " ui.button(name='submit', label='Next', primary=True),", " ])", " ]", " else:", " # If first time on this page, create the card.", " add_card(q, 'form', ui.form_card(box='vertical', items=[", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1'),", " ui.step(label='Step 2'),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox1', label='Textbox 1'),", " ui.buttons(justify='end', items=[", " ui.button(name='step2', label='Next', primary=True),", " ]),", " ]))", "", "", "async def init(q: Q) -> None:", " q.page['meta'] = ui.meta_card(box='', layouts=[ui.layout(breakpoint='xs', min_height='100vh', zones=[", " ui.zone('main', size='1', direction=ui.ZoneDirection.ROW, zones=[", " ui.zone('sidebar', size='250px'),", " ui.zone('body', zones=[", " ui.zone('content', zones=[", " # Specify various zones and use the one that is currently needed. Empty zones are ignored.", " ui.zone('horizontal', direction=ui.ZoneDirection.ROW),", " ui.zone('vertical'),", " ui.zone('grid', direction=ui.ZoneDirection.ROW, wrap='stretch', justify='center')", " ]),", " ]),", " ])", " ])])", " q.page['sidebar'] = ui.nav_card(", " box='sidebar', color='primary', title='My App', subtitle=\"Let's conquer the world!\",", " value=f'#{q.args[\"#\"]}' if q.args['#'] else '#page1',", " image='https://wave.h2o.ai/img/h2o-logo.svg', items=[", " ui.nav_group('Menu', items=[", " ui.nav_item(name='#page1', label='Home'),", " ui.nav_item(name='#page2', label='Charts'),", " ui.nav_item(name='#page3', label='Grid'),", " ui.nav_item(name='#page4', label='Form'),", " ]),", " ],", " secondary_items=[", " ui.persona(title='John Doe', subtitle='Developer', size='s',", " image='https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&h=750&w=1260'),", " ]", " )", "", " # If no active hash present, render page1.", " if q.args['#'] is None:", " await page1(q)", "", "", "@app('/')", "async def serve(q: Q):", " # Run only once per client connection.", " if not q.client.initialized:", " q.client.cards = set()", " await init(q)", " q.client.initialized = True", "", " # Handle routing.", " await handle_on(q)", " await q.page.save()", "" ], "description": "An app template with both sidebar and navigation." }, "Wave app template with a header navigation": { "prefix": "w_app_header_nav", "body": [ "from h2o_wave import main, app, Q, ui, on, handle_on, data", "from typing import Optional, List", "", "", "# Use for page cards that should be removed when navigating away.", "# For pages that should be always present on screen use q.page[key] = ...", "def add_card(q, name, card) -> None:", " q.client.cards.add(name)", " q.page[name] = card", "", "", "# Remove all the cards related to navigation.", "def clear_cards(q, ignore: Optional[List[str]] = []) -> None:", " if not q.client.cards:", " return", " for name in q.client.cards.copy():", " if name not in ignore:", " del q.page[name]", " q.client.cards.remove(name)", "", "", "@on('#page1')", "async def page1(q: Q):", " clear_cards(q) # When routing, drop all the cards except of the main ones (header, sidebar, meta).", "", " for i in range(3):", " add_card(q, f'info{i}', ui.tall_info_card(box='horizontal', name='', title='Speed',", " caption='The models are performant thanks to...', icon='SpeedHigh'))", " add_card(q, 'article', ui.tall_article_preview_card(", " box=ui.box('vertical', height='600px'), title='How does magic work',", " image='https://images.pexels.com/photos/624015/pexels-photo-624015.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1',", " content='''", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac sodales felis. Duis orci enim, iaculis at augue vel, mattis imperdiet ligula. Sed a placerat lacus, vitae viverra ante. Duis laoreet purus sit amet orci lacinia, non facilisis ipsum venenatis. Duis bibendum malesuada urna. Praesent vehicula tempor volutpat. In sem augue, blandit a tempus sit amet, tristique vehicula nisl. Duis molestie vel nisl a blandit. Nunc mollis ullamcorper elementum.", "Donec in erat augue. Nullam mollis ligula nec massa semper, laoreet pellentesque nulla ullamcorper. In ante ex, tristique et mollis id, facilisis non metus. Aliquam neque eros, semper id finibus eu, pellentesque ac magna. Aliquam convallis eros ut erat mollis, sit amet scelerisque ex pretium. Nulla sodales lacus a tellus molestie blandit. Praesent molestie elit viverra, congue purus vel, cursus sem. Donec malesuada libero ut nulla bibendum, in condimentum massa pretium. Aliquam erat volutpat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer vel tincidunt purus, congue suscipit neque. Fusce eget lacus nibh. Sed vestibulum neque id erat accumsan, a faucibus leo malesuada. Curabitur varius ligula a velit aliquet tincidunt. Donec vehicula ligula sit amet nunc tempus, non fermentum odio rhoncus.", "Vestibulum condimentum consectetur aliquet. Phasellus mollis at nulla vel blandit. Praesent at ligula nulla. Curabitur enim tellus, congue id tempor at, malesuada sed augue. Nulla in justo in libero condimentum euismod. Integer aliquet, velit id convallis maximus, nisl dui porta velit, et pellentesque ligula lorem non nunc. Sed tincidunt purus non elit ultrices egestas quis eu mauris. Sed molestie vulputate enim, a vehicula nibh pulvinar sit amet. Nullam auctor sapien est, et aliquet dui congue ornare. Donec pulvinar scelerisque justo, nec scelerisque velit maximus eget. Ut ac lectus velit. Pellentesque bibendum ex sit amet cursus commodo. Fusce congue metus at elementum ultricies. Suspendisse non rhoncus risus. In hac habitasse platea dictumst.", " '''", " ))", "", "", "@on('#page2')", "async def page2(q: Q):", " clear_cards(q) # When routing, drop all the cards except of the main ones (header, sidebar, meta).", " add_card(q, 'chart1', ui.plot_card(", " box='horizontal',", " title='Chart 1',", " data=data('category country product price', 10, rows=[", " ('G1', 'USA', 'P1', 124),", " ('G1', 'China', 'P2', 580),", " ('G1', 'USA', 'P3', 528),", " ('G1', 'China', 'P1', 361),", " ('G1', 'USA', 'P2', 228),", " ('G2', 'China', 'P3', 418),", " ('G2', 'USA', 'P1', 824),", " ('G2', 'China', 'P2', 539),", " ('G2', 'USA', 'P3', 712),", " ('G2', 'USA', 'P1', 213),", " ]),", " plot=ui.plot([ui.mark(type='interval', x='=product', y='=price', color='=country', stack='auto',", " dodge='=category', y_min=0)])", " ))", " add_card(q, 'chart2', ui.plot_card(", " box='horizontal',", " title='Chart 2',", " data=data('date price', 10, rows=[", " ('2020-03-20', 124),", " ('2020-05-18', 580),", " ('2020-08-24', 528),", " ('2020-02-12', 361),", " ('2020-03-11', 228),", " ('2020-09-26', 418),", " ('2020-11-12', 824),", " ('2020-12-21', 539),", " ('2020-03-18', 712),", " ('2020-07-11', 213),", " ]),", " plot=ui.plot([ui.mark(type='line', x_scale='time', x='=date', y='=price', y_min=0)])", " ))", " add_card(q, 'table', ui.form_card(box='vertical', items=[ui.table(", " name='table',", " downloadable=True,", " resettable=True,", " groupable=True,", " columns=[", " ui.table_column(name='text', label='Process', searchable=True),", " ui.table_column(name='tag', label='Status', filterable=True, cell_type=ui.tag_table_cell_type(", " name='tags',", " tags=[", " ui.tag(label='FAIL', color='\\$red'),", " ui.tag(label='DONE', color='#D2E3F8', label_color='#053975'),", " ui.tag(label='SUCCESS', color='\\$mint'),", " ]", " ))", " ],", " rows=[", " ui.table_row(name='row1', cells=['Process 1', 'FAIL']),", " ui.table_row(name='row2', cells=['Process 2', 'SUCCESS,DONE']),", " ui.table_row(name='row3', cells=['Process 3', 'DONE']),", " ui.table_row(name='row4', cells=['Process 4', 'FAIL']),", " ui.table_row(name='row5', cells=['Process 5', 'SUCCESS,DONE']),", " ui.table_row(name='row6', cells=['Process 6', 'DONE']),", " ])", " ]))", "", "", "@on('#page3')", "async def page3(q: Q):", " clear_cards(q) # When routing, drop all the cards except of the main ones (header, sidebar, meta).", "", " for i in range(12):", " add_card(q, f'item{i}', ui.wide_info_card(box=ui.box('grid', width='400px'), name='', title='Tile',", " caption='Lorem ipsum dolor sit amet'))", "", "", "@on('#page4')", "async def handle_page4(q: Q):", " # When routing, drop all the cards except of the main ones (header, sidebar, meta).", " # Since this page is interactive, we want to update its card instead of recreating it every time, so ignore 'form' card on drop.", " clear_cards(q, ['form'])", "", " if q.args.step1:", " # Just update the existing card, do not recreate.", " q.page['form'].items = [", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1'),", " ui.step(label='Step 2'),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox2', label='Textbox 1'),", " ui.buttons(justify='end', items=[", " ui.button(name='step2', label='Next', primary=True),", " ])", " ]", " elif q.args.step2:", " # Just update the existing card, do not recreate.", " q.page['form'].items = [", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1', done=True),", " ui.step(label='Step 2'),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox2', label='Textbox 2'),", " ui.buttons(justify='end', items=[", " ui.button(name='step1', label='Cancel'),", " ui.button(name='step3', label='Next', primary=True),", " ])", " ]", " elif q.args.step3:", " # Just update the existing card, do not recreate.", " q.page['form'].items = [", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1', done=True),", " ui.step(label='Step 2', done=True),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox3', label='Textbox 3'),", " ui.buttons(justify='end', items=[", " ui.button(name='step2', label='Cancel'),", " ui.button(name='submit', label='Next', primary=True),", " ])", " ]", " else:", " # If first time on this page, create the card.", " add_card(q, 'form', ui.form_card(box='vertical', items=[", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1'),", " ui.step(label='Step 2'),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox1', label='Textbox 1'),", " ui.buttons(justify='end', items=[", " ui.button(name='step2', label='Next', primary=True),", " ]),", " ]))", "", "", "async def init(q: Q) -> None:", " q.page['meta'] = ui.meta_card(box='', layouts=[ui.layout(breakpoint='xs', min_height='100vh', zones=[", " ui.zone('header'),", " ui.zone('content', zones=[", " # Specify various zones and use the one that is currently needed. Empty zones are ignored.", " ui.zone('horizontal', direction=ui.ZoneDirection.ROW),", " ui.zone('vertical'),", " ui.zone('grid', direction=ui.ZoneDirection.ROW, wrap='stretch', justify='center')", " ]),", " ])])", " q.page['header'] = ui.header_card(", " box='header', title='My app', subtitle=\"Let's conquer the world\",", " image='https://wave.h2o.ai/img/h2o-logo.svg',", " secondary_items=[", " ui.tabs(name='tabs', value=f'#{q.args[\"#\"]}' if q.args['#'] else '#page1', link=True, items=[", " ui.tab(name='#page1', label='Home'),", " ui.tab(name='#page2', label='Charts'),", " ui.tab(name='#page3', label='Grid'),", " ui.tab(name='#page4', label='Form'),", " ]),", " ],", " items=[", " ui.persona(title='John Doe', subtitle='Developer', size='xs',", " image='https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&h=750&w=1260'),", " ]", " )", " # If no active hash present, render page1.", " if q.args['#'] is None:", " await page1(q)", "", "", "@app('/')", "async def serve(q: Q):", " # Run only once per client connection.", " if not q.client.initialized:", " q.client.cards = set()", " await init(q)", " q.client.initialized = True", "", " # Handle routing.", " await handle_on(q)", " await q.page.save()", "", "" ], "description": "An app template with a header and navigation." }, "Wave app template with a header and sidebar navigation": { "prefix": "w_app_header_sidebar_nav", "body": [ "", "from h2o_wave import main, app, Q, ui, on, handle_on, data", "from typing import Optional, List", "", "", "# Use for page cards that should be removed when navigating away.", "# For pages that should be always present on screen use q.page[key] = ...", "def add_card(q, name, card) -> None:", " q.client.cards.add(name)", " q.page[name] = card", "", "", "# Remove all the cards related to navigation.", "def clear_cards(q, ignore: Optional[List[str]] = []) -> None:", " if not q.client.cards:", " return", "", " for name in q.client.cards.copy():", " if name not in ignore:", " del q.page[name]", " q.client.cards.remove(name)", "", "", "@on('#page1')", "async def page1(q: Q):", " q.page['sidebar'].value = '#page1'", " clear_cards(q) # When routing, drop all the cards except of the main ones (header, sidebar, meta).", "", " for i in range(3):", " add_card(q, f'info{i}', ui.tall_info_card(box='horizontal', name='', title='Speed',", " caption='The models are performant thanks to...', icon='SpeedHigh'))", " add_card(q, 'article', ui.tall_article_preview_card(", " box=ui.box('vertical', height='600px'), title='How does magic work',", " image='https://images.pexels.com/photos/624015/pexels-photo-624015.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1',", " content='''", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac sodales felis. Duis orci enim, iaculis at augue vel, mattis imperdiet ligula. Sed a placerat lacus, vitae viverra ante. Duis laoreet purus sit amet orci lacinia, non facilisis ipsum venenatis. Duis bibendum malesuada urna. Praesent vehicula tempor volutpat. In sem augue, blandit a tempus sit amet, tristique vehicula nisl. Duis molestie vel nisl a blandit. Nunc mollis ullamcorper elementum.", "Donec in erat augue. Nullam mollis ligula nec massa semper, laoreet pellentesque nulla ullamcorper. In ante ex, tristique et mollis id, facilisis non metus. Aliquam neque eros, semper id finibus eu, pellentesque ac magna. Aliquam convallis eros ut erat mollis, sit amet scelerisque ex pretium. Nulla sodales lacus a tellus molestie blandit. Praesent molestie elit viverra, congue purus vel, cursus sem. Donec malesuada libero ut nulla bibendum, in condimentum massa pretium. Aliquam erat volutpat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer vel tincidunt purus, congue suscipit neque. Fusce eget lacus nibh. Sed vestibulum neque id erat accumsan, a faucibus leo malesuada. Curabitur varius ligula a velit aliquet tincidunt. Donec vehicula ligula sit amet nunc tempus, non fermentum odio rhoncus.", "Vestibulum condimentum consectetur aliquet. Phasellus mollis at nulla vel blandit. Praesent at ligula nulla. Curabitur enim tellus, congue id tempor at, malesuada sed augue. Nulla in justo in libero condimentum euismod. Integer aliquet, velit id convallis maximus, nisl dui porta velit, et pellentesque ligula lorem non nunc. Sed tincidunt purus non elit ultrices egestas quis eu mauris. Sed molestie vulputate enim, a vehicula nibh pulvinar sit amet. Nullam auctor sapien est, et aliquet dui congue ornare. Donec pulvinar scelerisque justo, nec scelerisque velit maximus eget. Ut ac lectus velit. Pellentesque bibendum ex sit amet cursus commodo. Fusce congue metus at elementum ultricies. Suspendisse non rhoncus risus. In hac habitasse platea dictumst.", " '''", " ))", "", "", "@on('#page2')", "async def page2(q: Q):", " q.page['sidebar'].value = '#page2'", " clear_cards(q) # When routing, drop all the cards except of the main ones (header, sidebar, meta).", " add_card(q, 'chart1', ui.plot_card(", " box='horizontal',", " title='Chart 1',", " data=data('category country product price', 10, rows=[", " ('G1', 'USA', 'P1', 124),", " ('G1', 'China', 'P2', 580),", " ('G1', 'USA', 'P3', 528),", " ('G1', 'China', 'P1', 361),", " ('G1', 'USA', 'P2', 228),", " ('G2', 'China', 'P3', 418),", " ('G2', 'USA', 'P1', 824),", " ('G2', 'China', 'P2', 539),", " ('G2', 'USA', 'P3', 712),", " ('G2', 'USA', 'P1', 213),", " ]),", " plot=ui.plot([ui.mark(type='interval', x='=product', y='=price', color='=country', stack='auto',", " dodge='=category', y_min=0)])", " ))", " add_card(q, 'chart2', ui.plot_card(", " box='horizontal',", " title='Chart 2',", " data=data('date price', 10, rows=[", " ('2020-03-20', 124),", " ('2020-05-18', 580),", " ('2020-08-24', 528),", " ('2020-02-12', 361),", " ('2020-03-11', 228),", " ('2020-09-26', 418),", " ('2020-11-12', 824),", " ('2020-12-21', 539),", " ('2020-03-18', 712),", " ('2020-07-11', 213),", " ]),", " plot=ui.plot([ui.mark(type='line', x_scale='time', x='=date', y='=price', y_min=0)])", " ))", " add_card(q, 'table', ui.form_card(box='vertical', items=[ui.table(", " name='table',", " downloadable=True,", " resettable=True,", " groupable=True,", " columns=[", " ui.table_column(name='text', label='Process', searchable=True),", " ui.table_column(name='tag', label='Status', filterable=True, cell_type=ui.tag_table_cell_type(", " name='tags',", " tags=[", " ui.tag(label='FAIL', color='\\$red'),", " ui.tag(label='DONE', color='#D2E3F8', label_color='#053975'),", " ui.tag(label='SUCCESS', color='\\$mint'),", " ]", " ))", " ],", " rows=[", " ui.table_row(name='row1', cells=['Process 1', 'FAIL']),", " ui.table_row(name='row2', cells=['Process 2', 'SUCCESS,DONE']),", " ui.table_row(name='row3', cells=['Process 3', 'DONE']),", " ui.table_row(name='row4', cells=['Process 4', 'FAIL']),", " ui.table_row(name='row5', cells=['Process 5', 'SUCCESS,DONE']),", " ui.table_row(name='row6', cells=['Process 6', 'DONE']),", " ])", " ]))", "", "", "@on('#page3')", "async def page3(q: Q):", " q.page['sidebar'].value = '#page3'", " clear_cards(q) # When routing, drop all the cards except of the main ones (header, sidebar, meta).", "", " for i in range(12):", " add_card(q, f'item{i}', ui.wide_info_card(box=ui.box('grid', width='400px'), name='', title='Tile',", " caption='Lorem ipsum dolor sit amet'))", "", "", "@on('#page4')", "async def handle_page4(q: Q):", " q.page['sidebar'].value = '#page4'", " # When routing, drop all the cards except of the main ones (header, sidebar, meta).", " # Since this page is interactive, we want to update its card instead of recreating it every time, so ignore 'form' card on drop.", " clear_cards(q, ['form'])", "", " if q.args.step1:", " # Just update the existing card, do not recreate.", " q.page['form'].items = [", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1'),", " ui.step(label='Step 2'),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox2', label='Textbox 1'),", " ui.buttons(justify='end', items=[", " ui.button(name='step2', label='Next', primary=True),", " ])", " ]", " elif q.args.step2:", " # Just update the existing card, do not recreate.", " q.page['form'].items = [", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1', done=True),", " ui.step(label='Step 2'),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox2', label='Textbox 2'),", " ui.buttons(justify='end', items=[", " ui.button(name='step1', label='Cancel'),", " ui.button(name='step3', label='Next', primary=True),", " ])", " ]", " elif q.args.step3:", " # Just update the existing card, do not recreate.", " q.page['form'].items = [", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1', done=True),", " ui.step(label='Step 2', done=True),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox3', label='Textbox 3'),", " ui.buttons(justify='end', items=[", " ui.button(name='step2', label='Cancel'),", " ui.button(name='submit', label='Next', primary=True),", " ])", " ]", " else:", " # If first time on this page, create the card.", " add_card(q, 'form', ui.form_card(box='vertical', items=[", " ui.stepper(name='stepper', items=[", " ui.step(label='Step 1'),", " ui.step(label='Step 2'),", " ui.step(label='Step 3'),", " ]),", " ui.textbox(name='textbox1', label='Textbox 1'),", " ui.buttons(justify='end', items=[", " ui.button(name='step2', label='Next', primary=True),", " ]),", " ]))", "", "", "async def init(q: Q) -> None:", " q.page['meta'] = ui.meta_card(box='', layouts=[ui.layout(breakpoint='xs', min_height='100vh', zones=[", " ui.zone('main', size='1', direction=ui.ZoneDirection.ROW, zones=[", " ui.zone('sidebar', size='250px'),", " ui.zone('body', zones=[", " ui.zone('header'),", " ui.zone('content', zones=[", " # Specify various zones and use the one that is currently needed. Empty zones are ignored.", " ui.zone('horizontal', direction=ui.ZoneDirection.ROW),", " ui.zone('vertical'),", " ui.zone('grid', direction=ui.ZoneDirection.ROW, wrap='stretch', justify='center')", " ]),", " ]),", " ])", " ])])", " q.page['sidebar'] = ui.nav_card(", " box='sidebar', color='primary', title='My App', subtitle=\"Let's conquer the world!\",", " value=f'#{q.args[\"#\"]}' if q.args['#'] else '#page1',", " image='https://wave.h2o.ai/img/h2o-logo.svg', items=[", " ui.nav_group('Menu', items=[", " ui.nav_item(name='#page1', label='Home'),", " ui.nav_item(name='#page2', label='Charts'),", " ui.nav_item(name='#page3', label='Grid'),", " ui.nav_item(name='#page4', label='Form'),", " ]),", " ])", " q.page['header'] = ui.header_card(", " box='header', title='', subtitle='',", " secondary_items=[ui.textbox(name='search', icon='Search', width='400px', placeholder='Search...')],", " items=[", " ui.persona(title='John Doe', subtitle='Developer', size='xs',", " image='https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&h=750&w=1260'),", " ]", " )", " # If no active hash present, render page1.", " if q.args['#'] is None:", " await page1(q)", "", "", "@app('/')", "async def serve(q: Q):", " # Run only once per client connection.", " if not q.client.initialized:", " q.client.cards = set()", " await init(q)", " q.client.initialized = True", "", " # Handle routing.", " await handle_on(q)", " await q.page.save()", "", "" ], "description": "An app template with both sidebar, header and navigation." } }