Created
September 8, 2021 23:34
-
-
Save mtanco/5329a52f0713848eed0a98cc5982b602 to your computer and use it in GitHub Desktop.
Wave for Python Stock Ticker Sample App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
df = web.DataReader(stock, "yahoo", dt(2017, 1, 1), dt.now()).reset_index() | |
df["Date"] = df["Date"].apply(lambda d: pd.Timestamp(d).isoformat()) | |
print(df.head()) | |
q.page["card"] = ui.form_card( | |
box="1 1 12 10", | |
items=[ | |
ui.dropdown( | |
name="my-dropdown", | |
choices=[ | |
ui.choice("COKE", "Coke"), | |
ui.choice("TSLA", "Tesla"), | |
ui.choice("AAPL", "Apple"), | |
], | |
value=stock, | |
trigger=True | |
), | |
ui.visualization( | |
name="my-graph", | |
plot=ui.plot(marks=[ | |
ui.mark(type='line', x='=Date', x_scale="time", y='=Open', color="Green"), | |
ui.mark(type='line', x='=Date', x_scale="time", y='=Close', color="Red"), | |
]), | |
data=data( | |
fields=["Date", "Open", "Close"], | |
rows=df[["Date", "Open", "Close"]].values.tolist(), | |
pack=True, | |
), | |
) | |
] | |
) | |
await q.page.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment