Exemplo n.º 1
0
async def setup_page(q: Q):
    q.page['meta'] = ui.meta_card(
        box='',
        title=app_title,
        layouts=[
            ui.layout(breakpoint='xs',
                      zones=[
                          ui.zone('header'),
                          ui.zone('blurb'),
                          ui.zone('main',
                                  size='calc(100vh - 140px)',
                                  direction=ui.ZoneDirection.ROW,
                                  zones=[ui.zone('code'),
                                         ui.zone('preview')])
                      ])
        ])

    q.page['header'] = ui.header_card(
        box='header',
        title=app_title,
        subtitle=f'{len(catalog)} Interactive Examples',
        image=
        'https://www.h2o.ai/wp-content/themes/h2o2018/templates/dist/images/h2o_logo.svg',
        items=[
            ui.link(label='Wave docs',
                    path='https://wave.h2o.ai/docs/getting-started',
                    target='_blank'),
            ui.link(label='Discussions',
                    path='https://github.com/h2oai/wave/discussions',
                    target='_blank'),
            ui.link(label='Blog',
                    path='https://wave.h2o.ai/blog',
                    target='_blank'),
            ui.link(label='Hybrid Cloud',
                    path='https://www.h2o.ai/hybrid-cloud/',
                    target='_blank'),
            ui.link(label='H2O', path='https://www.h2o.ai/', target='_blank'),
        ])
    q.page['blurb'] = ui.section_card(box='blurb',
                                      title='',
                                      subtitle='',
                                      items=[])
    q.page['code'] = ui.frame_card(box='code', title='', content='')
    q.page['preview'] = ui.frame_card(box='preview',
                                      title='Preview',
                                      path=f'{_base_url}demo')

    await q.page.save()
Exemplo n.º 2
0
async def serve(q: Q):
    links = q.args.user_files
    if links:
        items = [ui.text_xl('Files uploaded!')]
        for link in links:
            local_path = await q.site.download(link, '.')
            #
            # The file is now available locally; process the file.
            # To keep this example simple, we just read the file size.
            #
            size = os.path.getsize(local_path)

            items.append(
                ui.link(label=f'{os.path.basename(link)} ({size} bytes)',
                        download=True,
                        path=link))
            # Clean up
            os.remove(local_path)

        items.append(ui.button(name='back', label='Back', primary=True))
        q.page['example'].items = items
    else:
        q.page['example'] = ui.form_card(box='1 1 4 10',
                                         items=[
                                             ui.text_xl('Upload some files'),
                                             ui.file_upload(name='user_files',
                                                            label='Upload',
                                                            multiple=True),
                                         ])
    await q.page.save()
Exemplo n.º 3
0
async def serve(q: Q):
    q.page['example'] = ui.form_card(box='1 1 4 10', items=[
        ui.text_xl(content='Extra-large text, for headings.'),
        ui.text_l(content='Large text, for sub-headings.'),
        ui.text_m(content='Body text, for paragraphs and other content.'),
        ui.text_s(content='Small text, for small print.'),
        ui.text_xs(content='Extra-small text, for really small print.'),
        ui.separator(label='A separator sections forms'),
        ui.progress(label='A progress bar'),
        ui.progress(label='A progress bar'),
        ui.message_bar(type='success', text='Message bar'),
        ui.textbox(name='textbox', label='Textbox'),
        ui.label(label='Checkboxes'),
        ui.checkbox(name='checkbox1', label='A checkbox'),
        ui.checkbox(name='checkbox1', label='Another checkbox'),
        ui.checkbox(name='checkbox1', label='Yet another checkbox'),
        ui.toggle(name='toggle', label='Toggle'),
        ui.choice_group(name='choice_group', label='Choice group', choices=[
            ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']
        ]),
        ui.checklist(name='checklist', label='Checklist', choices=[
            ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']
        ]),
        ui.dropdown(name='dropdown', label='Dropdown', choices=[
            ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']
        ]),
        ui.dropdown(name='dropdown', label='Multi-valued Dropdown', values=[], choices=[
            ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']
        ]),
        ui.combobox(name='combobox', label='Combobox', choices=['Choice 1', 'Choice 2', 'Choice 3']),
        ui.slider(name='slider', label='Slider'),
        ui.range_slider(name='range_slider', label='Range slider', max=99),
        ui.spinbox(name='spinbox', label='Spinbox'),
        ui.date_picker(name='date_picker', label='Date picker'),
        ui.color_picker(name='color_picker', label='Color picker'),
        ui.buttons([
            ui.button(name='primary_button', label='Primary', primary=True),
            ui.button(name='standard_button', label='Standard'),
            ui.button(name='standard_disabled_button', label='Standard', disabled=True),
        ]),
        ui.file_upload(name='file_upload', label='File upload'),
        ui.table(name='table', columns=[
            ui.table_column(name='col1', label='Column 1'),
            ui.table_column(name='col2', label='Column 2'),
        ], rows=[
            ui.table_row(name='row1', cells=['Text A', 'Text B']),
            ui.table_row(name='row2', cells=['Text C', 'Text D']),
            ui.table_row(name='row3', cells=['Text E', 'Text F']),
        ]),
        ui.link(label='Link'),
        ui.tabs(name='tabs', items=[
            ui.tab(name='email', label='Mail', icon='Mail'),
            ui.tab(name='events', label='Events', icon='Calendar'),
            ui.tab(name='spam', label='Spam'),
        ]),
        ui.expander(name='expander', label='Expander'),
        ui.frame(path='https://example.com'),
        ui.markup(content=html),
        ui.template(
            content=menu,
            data=pack(dict(dishes=[
                dict(name='Spam', price='$2.00'),
                dict(name='Ham', price='$3.45'),
                dict(name='Eggs', price='$1.75'),
            ]))
        ),
        ui.picker(name='picker', label='Picker', choices=[
            ui.choice('choice1', label='Choice 1'),
            ui.choice('choice2', label='Choice 2'),
            ui.choice('choice3', label='Choice 3'),
        ]),
        ui.stepper(name='stepper', items=[
            ui.step(label='Step 1', icon='MailLowImportance'),
            ui.step(label='Step 2', icon='TaskManagerMirrored'),
            ui.step(label='Step 3', icon='Cafe'),
        ]),
        ui.visualization(
            plot=ui.plot([ui.mark(type='interval', x='=product', y='=price', y_min=0)]),
            data=data(fields='product price', rows=[(c, x) for c, x, _ in [f.next() for _ in range(n)]], pack=True),
        ),
        ui.vega_visualization(
            specification=spec,
            data=data(fields=["a", "b"], rows=[
                ["A", rnd()], ["B", rnd()], ["C", rnd()],
                ["D", rnd()], ["E", rnd()], ["F", rnd()],
                ["G", rnd()], ["H", rnd()], ["I", rnd()]
            ], pack=True),
        ),
        ui.button(name='show_inputs', label='Submit', primary=True),
    ])
    await q.page.save()
Exemplo n.º 4
0
# Form / Link
# Use links to allow navigation to internal and external URLs.
# ---
from h2o_wave import site, ui

page = site['/demo']

page['example'] = ui.form_card(
    box='1 1 4 -1',
    items=[
        ui.link(label='Internal link', path='/starred'),
        ui.link(label='Internal link, new tab', path='/starred', target=''),
        ui.link(label='Internal link, new tab', path='/starred', target='_blank'),  # same as target=''
        ui.link(label='Internal link, disabled', path='/starred', disabled=True),
        ui.link(label='External link', path='https://h2o.ai'),
        ui.link(label='External link, new tab', path='https://h2o.ai', target=''),
        ui.link(label='External link, new tab', path='https://h2o.ai', target='_blank'),  # same as target=''
        ui.link(label='External link, disabled', path='https://h2o.ai', disabled=True),
    ]
)
page.save()
Exemplo n.º 5
0
# Form / Link
# Use link to allow #navigation to internal and external URLs.
# #form #link
# ---
from h2o_wave import site, ui

page = site['/demo']

page['example'] = ui.form_card(
    box='1 1 4 10',
    items=[
        ui.link(label='Internal link', path='/starred'),
        ui.link(label='Internal link, new tab', path='/starred', target=''),
        ui.link(label='Internal link, new tab',
                path='/starred',
                target='_blank'),  # same as target=''
        ui.link(label='Internal link, disabled',
                path='/starred',
                disabled=True),
        ui.link(label='External link', path='https://h2o.ai'),
        ui.link(label='External link, new tab',
                path='https://h2o.ai',
                target=''),
        ui.link(label='External link, new tab',
                path='https://h2o.ai',
                target='_blank'),  # same as target=''
        ui.link(label='External link, disabled',
                path='https://h2o.ai',
                disabled=True),
        ui.link(
            label='Download link',
Exemplo n.º 6
0
# Form / Links
# Use links to allow #navigation to multiple internal and external URLs.
# #form #link
# ---
from h2o_wave import site, ui

page = site['/demo']

page['example'] = ui.form_card(
    box='1 1 3 3',
    items=[
        ui.text_l(content='**Vertical set of links with a label**'),
        ui.links(label='Second Column',
                 items=[
                     ui.link(label='Sample link',
                             path='https://www.h2o.ai/',
                             target='_blank'),
                     ui.link(label='Sample link',
                             path='https://www.h2o.ai/',
                             target='_blank'),
                     ui.link(label='Sample link',
                             path='https://www.h2o.ai/',
                             target='_blank'),
                 ]),
        ui.text_l(content='**Horizontal set of links**'),
        ui.links(inline=True,
                 items=[
                     ui.link(label='Sample link',
                             path='https://www.h2o.ai/',
                             target='_blank'),
                     ui.link(label='Sample link',
async def responsive_layout(q: Q):
    if not q.user.columns:
        q.user.columns = [
            ui.table_column(name='Index',
                            label='Index',
                            searchable=True,
                            sortable=True,
                            data_type='number'),
            ui.table_column(name='Started', label='Started', searchable=True),
            ui.table_column(name='Ended', label='Ended', searchable=True),
            ui.table_column(name='Duration',
                            label='Duration (mins)',
                            data_type='number'),
            ui.table_column(name='Scores', label='Scores', data_type='number'),
        ]

    if not q.client.LB_columns:
        q.client.LB_columns = [
            ui.table_column(name='User',
                            label='User',
                            searchable=True,
                            max_width='100px'),
            ui.table_column(name='Scores',
                            label='Scores',
                            searchable=True,
                            max_width='100px',
                            sortable=True),
        ]

    q.page['meta'] = ui.meta_card(
        box='',
        title='Streak Counter',
        layouts=[
            ui.layout(
                # If the viewport width >= 0:
                breakpoint='xs',
                zones=[
                    # 80px high header
                    ui.zone('header', size='80px'),
                    # Use remaining space for content
                    ui.zone('content')
                ]),
            ui.layout(
                # If the viewport width >= 768:
                breakpoint='m',
                zones=[
                    # 80px high header
                    ui.zone('header', size='80px'),
                    # Use remaining space for body
                    ui.zone(
                        'body',
                        direction=ui.ZoneDirection.ROW,
                        zones=[
                            # 250px wide sidebar
                            ui.zone('sidebar', size='250px'),
                            # Use remaining space for content
                            ui.zone('content'),
                        ]),
                    ui.zone('footer'),
                ]),
            ui.layout(
                # If the viewport width >= 1200:
                breakpoint='xl',
                width='1200px',
                zones=[
                    # 80px high header
                    ui.zone('header', size='80px'),
                    # Use remaining space for body
                    ui.zone(
                        'body',
                        direction=ui.ZoneDirection.ROW,
                        zones=[
                            # 300px wide sidebar
                            ui.zone('sidebar', size='300px'),
                            # Use remaining space for other widgets
                            ui.zone(
                                'other',
                                zones=[
                                    # Use one half for charts
                                    ui.zone('charts',
                                            direction=ui.ZoneDirection.ROW),
                                    # Use other half for content
                                    ui.zone('content', size='500px'),
                                ]),
                        ]),
                    ui.zone('footer'),
                ])
        ])

    q.page['header'] = ui.header_card(
        # Place card in the header zone, regardless of viewport size.
        box='header',
        title='Code Streak Counter',
        subtitle='Count your programming Streak while staying healthy !!!',
    )
    q.page['LeaderBoard'] = ui.form_card(
        # If the viewport width >= 0, place in content zone.
        # If the viewport width >= 768, place in sidebar zone.
        # If the viewport width >= 1200, place in sidebar zone.
        box=ui.boxes('content', 'sidebar', 'sidebar'),
        # title='Leader Board',
        items=[
            ui.text_l(content=f"Hi {q.auth.username.capitalize()}..!"),
            ui.text_xl(
                content=
                f"Your Total Score: {q.user.stop_watch.df['Scores'].sum()}"),
            ui.table(
                name='leaderboard',
                columns=q.client.LB_columns,
                rows=[
                    ui.table_row(name=user, cells=[user, str(score)])
                    for user, score in q.app.lb_dict.items()
                ],
                groupable=False,
                downloadable=True,
                resettable=False,
                height='425px',
            ),
            ui.link(name='logout',
                    label='Log Out',
                    button=True,
                    path=f'/_logout',
                    target='_current')
        ],
    )
    q.page['stopwatch'] = ui.form_card(
        box=ui.boxes(
            # If the viewport width >= 0, place as second item in content zone.
            ui.box(zone='content', order=2),
            # If the viewport width >= 768, place in content zone.
            'content',
            # If the viewport width >= 1200, place as first item in charts zone, use 2 parts of available space.
            ui.box(zone='charts', order=1, size=2),
        ),
        items=[
            ui.text_xl(
                content=
                f"<h1><center>{str(q.user.stop_watch.minutes).zfill(2)} : {str(q.user.stop_watch.seconds).zfill(2)}</center></h1>"
            ),
            ui.text_l(content=f"<center>Lets crack some code!</center>"),
            ui.buttons([
                ui.button(name='start', label='Start', primary=True),
                ui.button(name='stop', label='Stop', primary=False)
            ],
                       justify='center')
        ],
    )
    q.page['UserStreaks'] = ui.markdown_card(
        box=ui.boxes(
            # If the viewport width >= 0, place as third item in content zone.
            ui.box(zone='content', order=3),
            # If the viewport width >= 768, place as second item in content zone.
            ui.box(zone='content', order=2),
            # If the viewport width >= 1200, place as second item in charts zone, use 1 part of available space.
            ui.box(zone='charts', order=2, size=1),
        ),
        title='User Streaks',
        content="""=Last Streak Started: {{streak_start}}

<p data-test='UserStreaks_Last_Ended'>Last Streak Ended: {{streak_end}}</p>

<p data-test='UserStreaks_Total_Streaks'>Total Streaks: {{total_streaks}}</p>

Total Coding Time: {{total_time}}
""",
        data=dict(streak_start=q.user.stop_watch.last_start,
                  streak_end=q.user.stop_watch.last_stop,
                  total_streaks=q.user.stop_watch.total_streaks,
                  total_time=f"{str(q.user.stop_watch.total_hours).zfill(2)} :\
                            {str(q.user.stop_watch.total_minutes).zfill(2)} : \
                            {str(q.user.stop_watch.total_seconds).zfill(2)}"))
    q.page['history'] = ui.form_card(
        box=ui.boxes(
            # If the viewport width >= 0, place as fourth item in content zone.
            ui.box(zone='content', order=4),
            # If the viewport width >= 768, place as third item in content zone.
            ui.box(zone='content', order=3),
            # If the viewport width >= 1200, place in content zone.
            'content'),
        items=[
            ui.table(name='streaks_table',
                     columns=q.user.columns,
                     rows=[
                         ui.table_row(name=str(row.Index + 1),
                                      cells=[
                                          str(row.Index + 1), row.Started,
                                          row.Ended,
                                          str(row.Duration),
                                          str(row.Scores)
                                      ])
                         for row in q.user.stop_watch.df.itertuples()
                     ],
                     groupable=False,
                     downloadable=True,
                     resettable=False,
                     height='425px')
        ],
        title='History',
    )
    q.page['footer'] = ui.footer_card(box='footer', caption='(c) 2021 H2O.ai ')
Exemplo n.º 8
0
async def serve(q: Q):
    if not q.client.initialized:
        image = 'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&h=750&w=1260'
        f = FakeCategoricalSeries()
        q.client.primary = '#000000'
        q.client.page = '#e2e2e2'
        q.client.card = '#ffffff'
        q.client.text = '#000000'
        q.page['meta'] = ui.meta_card(
            box='',
            theme='custom',
            layouts=[
                ui.layout(breakpoint='xs',
                          zones=[
                              ui.zone('header'),
                              ui.zone('content',
                                      direction=ui.ZoneDirection.ROW,
                                      zones=[
                                          ui.zone('colors', size='340px'),
                                          ui.zone('preview')
                                      ]),
                              ui.zone('footer')
                          ])
            ])
        q.page['header'] = ui.header_card(box='header',
                                          title='Theme generator',
                                          subtitle='Color your app easily',
                                          icon='Color',
                                          icon_color='$card')
        q.page['form'] = ui.form_card(box='colors',
                                      items=[
                                          ui.color_picker(
                                              name='primary',
                                              label='Primary',
                                              trigger=True,
                                              alpha=False,
                                              inline=True,
                                              value=q.client.primary),
                                          ui.color_picker(name='text',
                                                          label='Text',
                                                          trigger=True,
                                                          alpha=False,
                                                          inline=True,
                                                          value=q.client.text),
                                          ui.color_picker(name='card',
                                                          label='Card',
                                                          trigger=True,
                                                          alpha=False,
                                                          inline=True,
                                                          value=q.client.card),
                                          ui.color_picker(name='page',
                                                          label='Page',
                                                          trigger=True,
                                                          alpha=False,
                                                          inline=True,
                                                          value=q.client.page),
                                          ui.text_xl('Check contrast'),
                                          get_contrast('text', 'card', q),
                                          get_contrast('card', 'primary', q),
                                          get_contrast('text', 'page', q),
                                          get_contrast('page', 'primary', q),
                                          ui.text_xl('Copy code'),
                                          ui.frame(content=get_theme_code(q),
                                                   height='180px'),
                                      ])
        q.page['sample'] = ui.form_card(
            box='preview',
            items=[
                ui.text_xl(content='Sample App to show colors'),
                ui.progress(label='A progress bar'),
                ui.inline([
                    ui.checkbox(name='checkbox1',
                                label='A checkbox',
                                value=True),
                    ui.checkbox(name='checkbox2', label='Another checkbox'),
                    ui.checkbox(name='checkbox3',
                                label='Yet another checkbox'),
                    ui.toggle(name='toggle', label='Toggle', value=True),
                ]),
                ui.inline([
                    ui.date_picker(name='date_picker', label='Date picker'),
                    ui.picker(name='picker',
                              label='Picker',
                              choices=[
                                  ui.choice('choice1', label='Choice 1'),
                                  ui.choice('choice2', label='Choice 2'),
                                  ui.choice('choice3', label='Choice 3'),
                              ]),
                    ui.combobox(name='combobox',
                                label='Combobox',
                                choices=['Choice 1', 'Choice 2', 'Choice 3']),
                    ui.persona(title='John Doe',
                               subtitle='Data Scientist',
                               size='s',
                               image=image),
                ]),
                ui.slider(name='slider', label='Slider', value=70),
                ui.link(label='Link'),
                ui.inline(justify='between',
                          items=[
                              ui.stepper(name='stepper',
                                         width='500px',
                                         items=[
                                             ui.step(label='Step 1',
                                                     icon='MailLowImportance'),
                                             ui.step(
                                                 label='Step 2',
                                                 icon='TaskManagerMirrored'),
                                             ui.step(label='Step 3',
                                                     icon='Cafe'),
                                         ]),
                              ui.tabs(name='menu',
                                      value='email',
                                      items=[
                                          ui.tab(name='email',
                                                 label='Mail',
                                                 icon='Mail'),
                                          ui.tab(name='events',
                                                 label='Events',
                                                 icon='Calendar'),
                                          ui.tab(name='spam', label='Spam'),
                                      ]),
                          ]),
                ui.inline(items=[
                    ui.table(
                        name='table',
                        width='50%',
                        columns=[
                            ui.table_column(
                                name='name', label='Name', min_width='80px'),
                            ui.table_column(name='surname',
                                            label='Surname',
                                            filterable=True),
                            ui.table_column(name='age',
                                            label='Age',
                                            sortable=True),
                            ui.table_column(
                                name='progress',
                                label='Progress',
                                cell_type=ui.progress_table_cell_type(
                                    color='$themePrimary')),
                        ],
                        rows=[
                            ui.table_row(name='row1',
                                         cells=['John', 'Doe', '25', '0.90']),
                            ui.table_row(name='row2',
                                         cells=['Ann', 'Doe', '35', '0.75']),
                            ui.table_row(
                                name='row3',
                                cells=['Casey', 'Smith', '40', '0.33']),
                        ],
                        height='330px',
                    ),
                    ui.visualization(
                        width='50%',
                        plot=ui.plot([
                            ui.mark(type='interval',
                                    x='=product',
                                    y='=price',
                                    y_min=0)
                        ]),
                        data=data(fields='product price',
                                  rows=[(c, x) for c, x, _ in
                                        [f.next() for _ in range(20)]],
                                  pack=True),
                    ),
                ]),
                ui.buttons([
                    ui.button(name='primary_button',
                              label='Primary',
                              primary=True),
                    ui.button(name='standard_button', label='Standard'),
                    ui.button(name='standard_disabled_button',
                              label='Disabled',
                              disabled=True),
                    ui.button(name='icon_button',
                              icon='Heart',
                              caption='Tooltip text'),
                ]),
            ])
        q.page['footer'] = ui.footer_card(
            box='footer', caption='(c) 2021 H2O.ai. All rights reserved.')
        q.client.themes = [
            ui.theme(name='custom',
                     text=q.client.text,
                     card=q.client.card,
                     page=q.client.page,
                     primary=q.client.primary)
        ]
        q.client.initialized = True

    if q.args.primary:
        q.client.themes[0].primary = q.args.primary
        q.client.primary = q.args.primary
    if q.args.text:
        q.client.themes[0].text = q.args.text
        q.client.text = q.args.text
    if q.args.card:
        q.client.themes[0].card = q.args.card
        q.client.card = q.args.card
    if q.args.page:
        q.client.themes[0].page = q.args.page
        q.client.page = q.args.page

    q.page['meta'].themes = q.client.themes
    q.page['form'].items[5] = get_contrast('text', 'card', q)
    q.page['form'].items[6] = get_contrast('card', 'primary', q)
    q.page['form'].items[7] = get_contrast('text', 'page', q)
    q.page['form'].items[8] = get_contrast('page', 'primary', q)
    q.page['form'].items[10].frame.content = get_theme_code(q)
    await q.page.save()