Spaces:
Sleeping
Sleeping
Add data input and preview widgets
Browse files
app.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
@@ -98,7 +98,7 @@
|
|
98 |
},
|
99 |
{
|
100 |
"cell_type": "code",
|
101 |
-
"execution_count":
|
102 |
"metadata": {},
|
103 |
"outputs": [],
|
104 |
"source": [
|
@@ -114,7 +114,7 @@
|
|
114 |
},
|
115 |
{
|
116 |
"cell_type": "code",
|
117 |
-
"execution_count":
|
118 |
"metadata": {},
|
119 |
"outputs": [
|
120 |
{
|
@@ -161,12 +161,12 @@
|
|
161 |
"data": {
|
162 |
"application/vnd.holoviews_exec.v0+json": "",
|
163 |
"text/html": [
|
164 |
-
"<div id='
|
165 |
-
" <div id=\"
|
166 |
"</div>\n",
|
167 |
"<script type=\"application/javascript\">(function(root) {\n",
|
168 |
-
" var docs_json = {\"
|
169 |
-
" var render_items = [{\"docid\":\"
|
170 |
" var docs = Object.values(docs_json)\n",
|
171 |
" if (!docs) {\n",
|
172 |
" return\n",
|
@@ -230,7 +230,7 @@
|
|
230 |
},
|
231 |
"metadata": {
|
232 |
"application/vnd.holoviews_exec.v0+json": {
|
233 |
-
"id": "
|
234 |
}
|
235 |
},
|
236 |
"output_type": "display_data"
|
@@ -240,30 +240,45 @@
|
|
240 |
"# | export\n",
|
241 |
"pn.extension(\n",
|
242 |
" template=\"fast\",\n",
|
243 |
-
")\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
]
|
245 |
},
|
246 |
{
|
247 |
"cell_type": "code",
|
248 |
-
"execution_count":
|
249 |
"metadata": {},
|
250 |
"outputs": [],
|
251 |
"source": [
|
252 |
"# | export\n",
|
253 |
-
"
|
254 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
"\n",
|
|
|
256 |
"url = pn.widgets.TextAreaInput(name=\"url\", placeholder=\"Enter the url of the dataset\", value=\"https://raw.githubusercontent.com/holoviz/panel/main/examples/assets/occupancy.csv\");\n",
|
257 |
"file = pn.widgets.FileInput(\n",
|
258 |
" accept=\".csv\", name=\"Upload a CSV file\",\n",
|
259 |
-
")\n"
|
260 |
-
"\n",
|
261 |
-
"\n"
|
262 |
]
|
263 |
},
|
264 |
{
|
265 |
"cell_type": "code",
|
266 |
-
"execution_count":
|
267 |
"metadata": {},
|
268 |
"outputs": [],
|
269 |
"source": [
|
@@ -277,24 +292,38 @@
|
|
277 |
},
|
278 |
{
|
279 |
"cell_type": "code",
|
280 |
-
"execution_count":
|
281 |
"metadata": {},
|
282 |
"outputs": [],
|
283 |
"source": [
|
284 |
"# | export\n",
|
285 |
"\n",
|
286 |
"def get_data(switch: pn.widgets.Switch, url: pn.widgets.TextAreaInput, file: pn.widgets.FileInput):\n",
|
|
|
287 |
" if not switch:\n",
|
288 |
" df = pd.read_csv(url)\n",
|
289 |
-
" cols = df.columns\n",
|
290 |
-
" return pn.Row(df.head(), df.hvplot(x=cols[0], y=cols[1:]).opts(width=600, height=400))\n",
|
291 |
" else:\n",
|
292 |
" if file is None:\n",
|
293 |
" return \"No file selected\"\n",
|
294 |
" df = pd.read_csv(io.BytesIO(file))\n",
|
295 |
-
"
|
296 |
-
"
|
297 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
"\n",
|
299 |
"bound_data = pn.bind(get_data, switch=switch, url=url, file=file)\n",
|
300 |
"pn.Column(\n",
|
@@ -307,7 +336,7 @@
|
|
307 |
},
|
308 |
{
|
309 |
"cell_type": "code",
|
310 |
-
"execution_count":
|
311 |
"metadata": {},
|
312 |
"outputs": [],
|
313 |
"source": [
|
@@ -316,7 +345,7 @@
|
|
316 |
},
|
317 |
{
|
318 |
"cell_type": "code",
|
319 |
-
"execution_count":
|
320 |
"metadata": {},
|
321 |
"outputs": [],
|
322 |
"source": [
|
@@ -331,7 +360,7 @@
|
|
331 |
},
|
332 |
{
|
333 |
"cell_type": "code",
|
334 |
-
"execution_count":
|
335 |
"metadata": {},
|
336 |
"outputs": [],
|
337 |
"source": [
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 443,
|
6 |
"metadata": {},
|
7 |
"outputs": [
|
8 |
{
|
|
|
98 |
},
|
99 |
{
|
100 |
"cell_type": "code",
|
101 |
+
"execution_count": 444,
|
102 |
"metadata": {},
|
103 |
"outputs": [],
|
104 |
"source": [
|
|
|
114 |
},
|
115 |
{
|
116 |
"cell_type": "code",
|
117 |
+
"execution_count": 445,
|
118 |
"metadata": {},
|
119 |
"outputs": [
|
120 |
{
|
|
|
161 |
"data": {
|
162 |
"application/vnd.holoviews_exec.v0+json": "",
|
163 |
"text/html": [
|
164 |
+
"<div id='b5fd0d4c-3636-402e-8326-0f10242d08f9'>\n",
|
165 |
+
" <div id=\"c722f4ad-7a66-43bd-aa27-4bbc623a5c3b\" data-root-id=\"b5fd0d4c-3636-402e-8326-0f10242d08f9\" style=\"display: contents;\"></div>\n",
|
166 |
"</div>\n",
|
167 |
"<script type=\"application/javascript\">(function(root) {\n",
|
168 |
+
" var docs_json = {\"e30ff602-1ba7-4be0-bedb-9dd6b6301b42\":{\"version\":\"3.3.4\",\"title\":\"Bokeh Application\",\"roots\":[{\"type\":\"object\",\"name\":\"panel.models.browser.BrowserInfo\",\"id\":\"b5fd0d4c-3636-402e-8326-0f10242d08f9\"},{\"type\":\"object\",\"name\":\"panel.models.comm_manager.CommManager\",\"id\":\"bdb2d655-80ca-4e44-8b26-cf407eb5094a\",\"attributes\":{\"plot_id\":\"b5fd0d4c-3636-402e-8326-0f10242d08f9\",\"comm_id\":\"f44bac24631040bbbad6afae06c136a1\",\"client_comm_id\":\"8409efc1cf814db885afe27289332e40\"}}],\"defs\":[{\"type\":\"model\",\"name\":\"ReactiveHTML1\"},{\"type\":\"model\",\"name\":\"FlexBox1\",\"properties\":[{\"name\":\"align_content\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"align_items\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"flex_direction\",\"kind\":\"Any\",\"default\":\"row\"},{\"name\":\"flex_wrap\",\"kind\":\"Any\",\"default\":\"wrap\"},{\"name\":\"justify_content\",\"kind\":\"Any\",\"default\":\"flex-start\"}]},{\"type\":\"model\",\"name\":\"FloatPanel1\",\"properties\":[{\"name\":\"config\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"contained\",\"kind\":\"Any\",\"default\":true},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"right-top\"},{\"name\":\"offsetx\",\"kind\":\"Any\",\"default\":null},{\"name\":\"offsety\",\"kind\":\"Any\",\"default\":null},{\"name\":\"theme\",\"kind\":\"Any\",\"default\":\"primary\"},{\"name\":\"status\",\"kind\":\"Any\",\"default\":\"normalized\"}]},{\"type\":\"model\",\"name\":\"GridStack1\",\"properties\":[{\"name\":\"mode\",\"kind\":\"Any\",\"default\":\"warn\"},{\"name\":\"ncols\",\"kind\":\"Any\",\"default\":null},{\"name\":\"nrows\",\"kind\":\"Any\",\"default\":null},{\"name\":\"allow_resize\",\"kind\":\"Any\",\"default\":true},{\"name\":\"allow_drag\",\"kind\":\"Any\",\"default\":true},{\"name\":\"state\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"drag1\",\"properties\":[{\"name\":\"slider_width\",\"kind\":\"Any\",\"default\":5},{\"name\":\"slider_color\",\"kind\":\"Any\",\"default\":\"black\"},{\"name\":\"value\",\"kind\":\"Any\",\"default\":50}]},{\"type\":\"model\",\"name\":\"click1\",\"properties\":[{\"name\":\"terminal_output\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"debug_name\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"clears\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"copy_to_clipboard1\",\"properties\":[{\"name\":\"fill\",\"kind\":\"Any\",\"default\":\"none\"},{\"name\":\"value\",\"kind\":\"Any\",\"default\":null}]},{\"type\":\"model\",\"name\":\"FastWrapper1\",\"properties\":[{\"name\":\"object\",\"kind\":\"Any\",\"default\":null},{\"name\":\"style\",\"kind\":\"Any\",\"default\":null}]},{\"type\":\"model\",\"name\":\"NotificationAreaBase1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"NotificationArea1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"notifications\",\"kind\":\"Any\",\"default\":[]},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0},{\"name\":\"types\",\"kind\":\"Any\",\"default\":[{\"type\":\"map\",\"entries\":[[\"type\",\"warning\"],[\"background\",\"#ffc107\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-exclamation-triangle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]},{\"type\":\"map\",\"entries\":[[\"type\",\"info\"],[\"background\",\"#007bff\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-info-circle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]}]}]},{\"type\":\"model\",\"name\":\"Notification\",\"properties\":[{\"name\":\"background\",\"kind\":\"Any\",\"default\":null},{\"name\":\"duration\",\"kind\":\"Any\",\"default\":3000},{\"name\":\"icon\",\"kind\":\"Any\",\"default\":null},{\"name\":\"message\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"notification_type\",\"kind\":\"Any\",\"default\":null},{\"name\":\"_destroyed\",\"kind\":\"Any\",\"default\":false}]},{\"type\":\"model\",\"name\":\"TemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"BootstrapTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"MaterialTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]}]}};\n",
|
169 |
+
" var render_items = [{\"docid\":\"e30ff602-1ba7-4be0-bedb-9dd6b6301b42\",\"roots\":{\"b5fd0d4c-3636-402e-8326-0f10242d08f9\":\"c722f4ad-7a66-43bd-aa27-4bbc623a5c3b\"},\"root_ids\":[\"b5fd0d4c-3636-402e-8326-0f10242d08f9\"]}];\n",
|
170 |
" var docs = Object.values(docs_json)\n",
|
171 |
" if (!docs) {\n",
|
172 |
" return\n",
|
|
|
230 |
},
|
231 |
"metadata": {
|
232 |
"application/vnd.holoviews_exec.v0+json": {
|
233 |
+
"id": "b5fd0d4c-3636-402e-8326-0f10242d08f9"
|
234 |
}
|
235 |
},
|
236 |
"output_type": "display_data"
|
|
|
240 |
"# | export\n",
|
241 |
"pn.extension(\n",
|
242 |
" template=\"fast\",\n",
|
243 |
+
")\n",
|
244 |
+
"pn.Column(\n",
|
245 |
+
" pn.pane.Markdown(\n",
|
246 |
+
" \"\"\"\n",
|
247 |
+
" # Welcome to the Interactive Data App\n",
|
248 |
+
"\n",
|
249 |
+
" This app allows you to interact with the data in a number of ways.\n",
|
250 |
+
" \"\"\"\n",
|
251 |
+
" )\n",
|
252 |
+
").servable(target=\"sidebar\");"
|
253 |
]
|
254 |
},
|
255 |
{
|
256 |
"cell_type": "code",
|
257 |
+
"execution_count": 446,
|
258 |
"metadata": {},
|
259 |
"outputs": [],
|
260 |
"source": [
|
261 |
"# | export\n",
|
262 |
+
"pn.Column(\n",
|
263 |
+
" pn.pane.Markdown(\n",
|
264 |
+
" \"\"\"\n",
|
265 |
+
" ## Data Input\n",
|
266 |
+
"\n",
|
267 |
+
" You can either input the URL of a dataset or upload a file.\n",
|
268 |
+
" \"\"\"\n",
|
269 |
+
" ),\n",
|
270 |
+
").servable(target=\"sidebar\");\n",
|
271 |
"\n",
|
272 |
+
"switch = pn.widgets.Switch(name=\"URL - FILE\", value=False)\n",
|
273 |
"url = pn.widgets.TextAreaInput(name=\"url\", placeholder=\"Enter the url of the dataset\", value=\"https://raw.githubusercontent.com/holoviz/panel/main/examples/assets/occupancy.csv\");\n",
|
274 |
"file = pn.widgets.FileInput(\n",
|
275 |
" accept=\".csv\", name=\"Upload a CSV file\",\n",
|
276 |
+
")\n"
|
|
|
|
|
277 |
]
|
278 |
},
|
279 |
{
|
280 |
"cell_type": "code",
|
281 |
+
"execution_count": 447,
|
282 |
"metadata": {},
|
283 |
"outputs": [],
|
284 |
"source": [
|
|
|
292 |
},
|
293 |
{
|
294 |
"cell_type": "code",
|
295 |
+
"execution_count": 448,
|
296 |
"metadata": {},
|
297 |
"outputs": [],
|
298 |
"source": [
|
299 |
"# | export\n",
|
300 |
"\n",
|
301 |
"def get_data(switch: pn.widgets.Switch, url: pn.widgets.TextAreaInput, file: pn.widgets.FileInput):\n",
|
302 |
+
" df = None\n",
|
303 |
" if not switch:\n",
|
304 |
" df = pd.read_csv(url)\n",
|
|
|
|
|
305 |
" else:\n",
|
306 |
" if file is None:\n",
|
307 |
" return \"No file selected\"\n",
|
308 |
" df = pd.read_csv(io.BytesIO(file))\n",
|
309 |
+
" \n",
|
310 |
+
" widget = pn.Column(\n",
|
311 |
+
" pn.pane.Markdown(\n",
|
312 |
+
" \"\"\"\n",
|
313 |
+
" ## Data Preview\n",
|
314 |
+
"\n",
|
315 |
+
" Here is a preview of the data.\n",
|
316 |
+
" \"\"\"\n",
|
317 |
+
" ),\n",
|
318 |
+
" pn.pane.Markdown(f\"### Data Shape: {df.shape}\"),\n",
|
319 |
+
" pn.pane.Markdown(f\"### Data Head\"),\n",
|
320 |
+
" pn.pane.DataFrame(df.head(5)),\n",
|
321 |
+
" pn.pane.Markdown(f\"### Describe\"),\n",
|
322 |
+
" pn.pane.DataFrame(df.describe()),\n",
|
323 |
+
" \n",
|
324 |
+
" )\n",
|
325 |
+
" return widget\n",
|
326 |
+
" \n",
|
327 |
"\n",
|
328 |
"bound_data = pn.bind(get_data, switch=switch, url=url, file=file)\n",
|
329 |
"pn.Column(\n",
|
|
|
336 |
},
|
337 |
{
|
338 |
"cell_type": "code",
|
339 |
+
"execution_count": 449,
|
340 |
"metadata": {},
|
341 |
"outputs": [],
|
342 |
"source": [
|
|
|
345 |
},
|
346 |
{
|
347 |
"cell_type": "code",
|
348 |
+
"execution_count": 450,
|
349 |
"metadata": {},
|
350 |
"outputs": [],
|
351 |
"source": [
|
|
|
360 |
},
|
361 |
{
|
362 |
"cell_type": "code",
|
363 |
+
"execution_count": 451,
|
364 |
"metadata": {},
|
365 |
"outputs": [],
|
366 |
"source": [
|
app.py
CHANGED
@@ -16,20 +16,34 @@ import io
|
|
16 |
pn.extension(
|
17 |
template="fast",
|
18 |
)
|
|
|
|
|
|
|
|
|
19 |
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# %% app.ipynb 3
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
|
|
25 |
url = pn.widgets.TextAreaInput(name="url", placeholder="Enter the url of the dataset", value="https://raw.githubusercontent.com/holoviz/panel/main/examples/assets/occupancy.csv");
|
26 |
file = pn.widgets.FileInput(
|
27 |
accept=".csv", name="Upload a CSV file",
|
28 |
)
|
29 |
|
30 |
|
31 |
-
|
32 |
-
|
33 |
# %% app.ipynb 4
|
34 |
def show_input_widget(switch: pn.widgets.Switch):
|
35 |
if not switch:
|
@@ -40,17 +54,31 @@ def show_input_widget(switch: pn.widgets.Switch):
|
|
40 |
|
41 |
# %% app.ipynb 5
|
42 |
def get_data(switch: pn.widgets.Switch, url: pn.widgets.TextAreaInput, file: pn.widgets.FileInput):
|
|
|
43 |
if not switch:
|
44 |
df = pd.read_csv(url)
|
45 |
-
cols = df.columns
|
46 |
-
return pn.Row(df.head(), df.hvplot(x=cols[0], y=cols[1:]).opts(width=600, height=400))
|
47 |
else:
|
48 |
if file is None:
|
49 |
return "No file selected"
|
50 |
df = pd.read_csv(io.BytesIO(file))
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
bound_data = pn.bind(get_data, switch=switch, url=url, file=file)
|
56 |
pn.Column(
|
|
|
16 |
pn.extension(
|
17 |
template="fast",
|
18 |
)
|
19 |
+
pn.Column(
|
20 |
+
pn.pane.Markdown(
|
21 |
+
"""
|
22 |
+
# Welcome to the Interactive Data App
|
23 |
|
24 |
+
This app allows you to interact with the data in a number of ways.
|
25 |
+
"""
|
26 |
+
)
|
27 |
+
).servable(target="sidebar");
|
28 |
|
29 |
# %% app.ipynb 3
|
30 |
+
pn.Column(
|
31 |
+
pn.pane.Markdown(
|
32 |
+
"""
|
33 |
+
## Data Input
|
34 |
+
|
35 |
+
You can either input the URL of a dataset or upload a file.
|
36 |
+
"""
|
37 |
+
),
|
38 |
+
).servable(target="sidebar");
|
39 |
|
40 |
+
switch = pn.widgets.Switch(name="URL - FILE", value=False)
|
41 |
url = pn.widgets.TextAreaInput(name="url", placeholder="Enter the url of the dataset", value="https://raw.githubusercontent.com/holoviz/panel/main/examples/assets/occupancy.csv");
|
42 |
file = pn.widgets.FileInput(
|
43 |
accept=".csv", name="Upload a CSV file",
|
44 |
)
|
45 |
|
46 |
|
|
|
|
|
47 |
# %% app.ipynb 4
|
48 |
def show_input_widget(switch: pn.widgets.Switch):
|
49 |
if not switch:
|
|
|
54 |
|
55 |
# %% app.ipynb 5
|
56 |
def get_data(switch: pn.widgets.Switch, url: pn.widgets.TextAreaInput, file: pn.widgets.FileInput):
|
57 |
+
df = None
|
58 |
if not switch:
|
59 |
df = pd.read_csv(url)
|
|
|
|
|
60 |
else:
|
61 |
if file is None:
|
62 |
return "No file selected"
|
63 |
df = pd.read_csv(io.BytesIO(file))
|
64 |
+
|
65 |
+
widget = pn.Column(
|
66 |
+
pn.pane.Markdown(
|
67 |
+
"""
|
68 |
+
## Data Preview
|
69 |
+
|
70 |
+
Here is a preview of the data.
|
71 |
+
"""
|
72 |
+
),
|
73 |
+
pn.pane.Markdown(f"### Data Shape: {df.shape}"),
|
74 |
+
pn.pane.Markdown(f"### Data Head"),
|
75 |
+
pn.pane.DataFrame(df.head(5)),
|
76 |
+
pn.pane.Markdown(f"### Describe"),
|
77 |
+
pn.pane.DataFrame(df.describe()),
|
78 |
+
|
79 |
+
)
|
80 |
+
return widget
|
81 |
+
|
82 |
|
83 |
bound_data = pn.bind(get_data, switch=switch, url=url, file=file)
|
84 |
pn.Column(
|