-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotdata_basic.py
More file actions
76 lines (60 loc) · 1.57 KB
/
hotdata_basic.py
File metadata and controls
76 lines (60 loc) · 1.57 KB
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
import marimo
__generated_with = "0.23.5"
app = marimo.App()
@app.cell
def _():
import os
import marimo as mo
import hotdata_marimo as hm
return hm, mo, os
@app.cell
def _(hm, mo, os):
mo.stop(
not (
os.environ.get("HOTDATA_API_KEY")
or os.environ.get("HOTDATA_TOKEN")
),
mo.callout(
mo.md(
"Add **HOTDATA_API_KEY** (or **HOTDATA_TOKEN**) to your environment "
"to run this example."
),
kind="warn",
),
)
client = hm.from_env()
return (client,)
@app.cell
def _(client, hm, mo):
id_map = client.connection_id_by_name()
tpch_id = id_map.get("tpch")
mo.stop(
not tpch_id,
mo.callout(
mo.md(
"This example expects a connection named **tpch**. "
"Create it in Hotdata or adjust the name in the notebook."
),
kind="warn",
),
)
browser = hm.table_browser(client, connection_id=tpch_id)
editor = hm.sql_editor(
client,
default_sql="SELECT * FROM tpch.tpch_sf1.nation LIMIT 5",
)
return browser, editor
@app.cell
def _(browser, editor, mo):
mo.vstack([browser.ui, editor.ui], gap=2)
return
@app.cell
def _(editor, hm):
# Explicitly touch nested widget values so Marimo reruns this cell on clicks.
_run = editor.run.value
_rerun = editor.rerun.value
_clear = editor.clear.value
hm.query_result(editor.result)
return _clear, _rerun, _run
if __name__ == "__main__":
app.run()