Skip to content

Commit

Permalink
Nebari demo video (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavithraes authored Aug 28, 2024
1 parent 43cc0cb commit d930e8c
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 37 deletions.
25 changes: 14 additions & 11 deletions 02-conda-store.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"source": [
"# Manage environments\n",
"\n",
"Create a new data science environment with the libraries you need for your work. Go to \"Services\" -> \"Environment management\" and follow the instructions in this [tutorial](https://conda.store/conda-store-ui/tutorials/create-envs)."
"Create a new data science environment with the libraries you need for your work. Go to \"Services\" -> \"Environment management\" and follow the instructions in this [tutorial](https://conda.store/conda-store-ui/tutorials/create-envs).\n",
"\n",
"Let's try some Polars examples: https://docs.pola.rs/user-guide/getting-started/"
]
},
{
Expand All @@ -17,16 +19,17 @@
"metadata": {},
"outputs": [],
"source": [
"import polars as pl\n",
"\n",
"q = (\n",
" pl.scan_csv(\"docs/data/iris.csv\")\n",
" .filter(pl.col(\"sepal_length\") > 5)\n",
" .group_by(\"species\")\n",
" .agg(pl.all().sum())\n",
")\n",
"\n",
"df = q.collect()"
"import polars as pl"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc9aee9a-c99f-4749-9d92-45bba4a16ead",
"metadata": {},
"outputs": [],
"source": [
"# TODO: Add your Polars code"
]
},
{
Expand Down
101 changes: 87 additions & 14 deletions 03-app-sharing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "7a4de979-d4c3-4e7e-bca1-09122e862e5b",
"id": "e4ae0e94-d2ea-431d-a3fd-05b8652148cc",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,15 +25,77 @@
"from sklearn.cluster import KMeans\n",
"from bokeh.sampledata import iris\n",
"\n",
"pn.extension()\n",
"\n",
"pn.extension()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cdaac3fb-adb2-426d-89eb-c34f3a685426",
"metadata": {},
"outputs": [],
"source": [
"flowers = iris.flowers.copy()\n",
"cols = list(flowers.columns)[:-1]\n",
"\n",
"cols = list(flowers.columns)[:-1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e52853f3-0556-4f9a-a49f-8b5987f57790",
"metadata": {},
"outputs": [],
"source": [
"x = pn.widgets.Select(name='x', options=cols)\n",
"x"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23513293-bcbc-4263-b3bd-faf9fe18405f",
"metadata": {},
"outputs": [],
"source": [
"y = pn.widgets.Select(name='y', options=cols, value='sepal_width')\n",
"y"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "99e6275d-4f2d-45e0-b803-40e2304531e9",
"metadata": {},
"outputs": [],
"source": [
"n_clusters = pn.widgets.IntSlider(name='n_clusters', start=1, end=5, value=3)\n",
"n_clusters"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dd2382ca-5c85-4fd3-9b75-2b31aac9cc1c",
"metadata": {},
"outputs": [],
"source": [
"widgets = pn.WidgetBox(\n",
" pn.Column(\n",
" \"\"\"This app provides an example of **building a simple dashboard using Panel**.\\n\\nIt demonstrates how to take the output of **k-means clustering on the Iris dataset** using scikit-learn, parameterizing the number of clusters and the variables to plot.\\n\\nThe entire clustering and plotting pipeline is expressed as a **single reactive function** that responsively returns an updated plot when one of the widgets changes.\\n\\n The **`x` marks the center** of the cluster.\"\"\",\n",
" x, y, n_clusters\n",
" )\n",
")\n",
"\n",
"widgets"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5102827d-8a22-4e04-81af-fd4b1bc6035a",
"metadata": {},
"outputs": [],
"source": [
"def get_clusters(x, y, n_clusters):\n",
" kmeans = KMeans(n_clusters=n_clusters, n_init='auto')\n",
" est = kmeans.fit(iris.flowers.iloc[:, :-1].values)\n",
Expand All @@ -48,23 +110,34 @@
" )\n",
" )\n",
"\n",
"widgets = pn.WidgetBox(\n",
" pn.Column(\n",
" \"\"\"This app provides an example of **building a simple dashboard using Panel**.\\n\\nIt demonstrates how to take the output of **k-means clustering on the Iris dataset** using scikit-learn, parameterizing the number of clusters and the variables to plot.\\n\\nThe entire clustering and plotting pipeline is expressed as a **single reactive function** that responsively returns an updated plot when one of the widgets changes.\\n\\n The **`x` marks the center** of the cluster.\"\"\",\n",
" x, y, n_clusters\n",
" )\n",
")\n",
"\n",
"clusters = pn.pane.HoloViews(\n",
" pn.bind(get_clusters, x, y, n_clusters), sizing_mode='stretch_width'\n",
")\n",
"\n",
"clusters"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7563992f-cc28-4271-9c65-00b880824c60",
"metadata": {},
"outputs": [],
"source": [
"dashboard = pn.template.MaterialTemplate(\n",
" title=\"Iris K-Means Clustering\",\n",
" sidebar=[widgets],\n",
" main=[clusters],\n",
")\n",
"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "49041ce0-0569-4952-8244-341bcf52a621",
"metadata": {},
"outputs": [],
"source": [
"dashboard.servable()"
]
},
Expand Down
49 changes: 39 additions & 10 deletions 04-dask.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
"metadata": {},
"outputs": [],
"source": [
"from dask_gateway import Gateway"
"from dask_gateway import Gateway\n",
"import dask.dataframe as dd\n",
"\n",
"import hvplot\n",
"import hvplot.dask"
]
},
{
Expand Down Expand Up @@ -66,16 +70,41 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b15ccbef-9f01-4775-b082-dc24d96c061d",
"id": "530dcbdb-5a4f-497e-9d8b-c00a9bb10f60",
"metadata": {},
"outputs": [],
"source": [
"import dask.array as da\n",
"\n",
"x = da.random.random((10000, 10000))\n",
"y = (x + x.T) - x.mean(axis=1)\n",
"\n",
"z = y.var(axis=0).compute()"
"ddf = dd.read_parquet(\"gcs://quansight-datasets/airline-ontime-performance/sorted/parquet_by_year\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9da49eb2-ee57-409a-a3bf-73e2c6cc196f",
"metadata": {},
"outputs": [],
"source": [
"ddf.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "68434394-929a-4503-a149-6bd78bb96ab1",
"metadata": {},
"outputs": [],
"source": [
"hvplot.extension('bokeh')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1324da8a-5ac8-4639-85ee-1bc393f27e4a",
"metadata": {},
"outputs": [],
"source": [
"ddf.groupby(\"FL_DATE\")[\"CANCELLED\"].count().hvplot()"
]
},
{
Expand Down Expand Up @@ -110,9 +139,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "global-global-demo",
"display_name": "global-global-demo-dask",
"language": "python",
"name": "conda-env-global-global-demo-py"
"name": "conda-env-global-global-demo-dask-py"
},
"language_info": {
"codemirror_mode": {
Expand Down
13 changes: 11 additions & 2 deletions 06-workflows.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
{
"cell_type": "code",
"execution_count": null,
"id": "a4918333-770a-4a71-a09a-57c031a5ea71",
"id": "5428a803-5ae3-460f-8963-7325282a1e51",
"metadata": {},
"outputs": [],
"source": [
"nebari_events[0]"
"for i in range(3):\n",
" print(f\"Member: {nebari_events[i]['actor']['login']} \\nEvent: {nebari_events[i][\"type\"]} \\nTime: {nebari_events[i]['created_at']} \\n\")"
]
},
{
Expand All @@ -60,6 +61,14 @@
"with open('nebari_events.txt', 'a') as f:\n",
" f.write(str(nebari_events))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b4cd968a-a375-4435-a036-9b0feb20edc9",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit d930e8c

Please sign in to comment.