File size: 45,164 Bytes
7fb4051
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
{
  "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."
  }
}