Skip to content

Instantly share code, notes, and snippets.

@mtanco
mtanco / wave_plot_from_pandas.py
Created December 20, 2020 18:31
Example of how to format a pandas dataframe for plotting with native Wave plot functions
# Plot / Dataframe
# Examples of how to format pandas data when plotting
# Use the `tolist()` function on `df.columns` and `df.values` along with Wave's `data` class
# ---
from h2o_wave import site, data, ui, main
import pandas as pd
import numpy as np
# Page to hold our charts
page = site['/demo']
@mtanco
mtanco / wave_use_uploaded_data.py
Last active February 26, 2021 04:15
wave_use_uploaded_data
import os
import time
from h2o_wave import main, app, Q, ui, data
import pandas as pd
import numpy as np
@app('/')
async def serve(q: Q):
print(q.args)
@mtanco
mtanco / wave_started_app.py
Created March 19, 2021 17:52
Starter code I have been using for most new apps
from h2o_wave import main, app, Q, ui, handle_on, on, data
from loguru import logger
def on_startup():
"""
Runs when the app is started, even if there are no browsers connected
:return:
"""
logger.info('http://localhost:10101/')
@mtanco
mtanco / testing_handlers_and_args.py
Created March 25, 2021 20:49
This is a simple app for understanding the behavior of `handle_on` and when `q.arg` dictionary is cleared.
from h2o_wave import main, app, Q, ui, on, handle_on
@app('/')
async def serve(q: Q):
if not q.client.initialized: # first time a tab comes this is app
q.page['a'] = ui.form_card(
box='4 3 4 2',
items=[
ui.textbox(name='color_textbox', placeholder='Purple'),
@mtanco
mtanco / exploring_stat_cards.py
Created March 26, 2021 17:27
This example script explores how to display stat cards nicely on a layout
from h2o_wave import main, site, Q, ui
def create_stat_card(name: str, n: int):
page[name] = ui.tall_gauge_stat_card(
box=ui.box(zone='body', width='200px', height='200px'),
title='test '*n,
value=str(n),
aux_value=str(n*100),
progress=n*0.1,
@mtanco
mtanco / permanate_cards.py
Last active April 27, 2021 18:21
The example application creates a new card from user text, all past cards stay on the page, and cards can be cleared with an additional button
from datetime import datetime
from h2o_wave import main, app, Q, ui, on, handle_on
from loguru import logger
def on_startup():
logger.info('http://localhost:10101')
@mtanco
mtanco / wave_background_tests.py
Created May 5, 2021 16:41
This Gist extends the https://wave.h2o.ai/docs/examples/background/ example and shows that apps are still interactive while running background tasks.
import time
import random
from h2o_wave import main, app, Q, ui
def sleeper_agent(secs) -> str:
time.sleep(secs) # Blocks!
return f'Done waiting for {secs} seconds!'
@mtanco
mtanco / ScheduledInteractiveApp.py
Last active May 11, 2021 19:46
Use the AsyncIOScheduler to run a scheduled job for updating a dashboard while maintaining the ability to use all features of an interactive app
import random
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from h2o_wave import main, app, Q, ui, handle_on, on, data
SCHEDULER = AsyncIOScheduler()
@app('/')
@mtanco
mtanco / stock_ticker_wave.py
Created September 8, 2021 23:34
Wave for Python Stock Ticker Sample App
from h2o_wave import main, app, ui, Q, on, handle_on, data
from pandas_datareader import data as web
import pandas as pd
from datetime import datetime as dt
@app("/")
async def serve(q: Q):
stock = q.args["my-dropdown"] or "COKE"
@mtanco
mtanco / mlops_predictions.py
Created September 24, 2021 17:10
An example of how to get predictions from a REST endpoint.
import json
import numpy as np
import pandas as pd
import requests
"""
Suggestions on how to use this in an H2O Wave app:
1. Have a page with a textbox asking users for a URL of a REST endpoint
2. Allow users to upload a CSV with new data