Skip to content

Commit ea43654

Browse files
committed
add toggle for showing/hiding code
1 parent 24b80de commit ea43654

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

demo/voila_demo.ipynb

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,24 @@
351351
" atl06_rsps.leaflet.redraw()\n",
352352
"\n",
353353
"# show code action\n",
354+
"global code06_is_shown\n",
355+
"code06_is_shown = False\n",
354356
"def on_show_code06_clicked(b):\n",
355-
" global url_textbox, atl06_parms\n",
357+
" global url_textbox, atl06_parms, code06_is_shown\n",
356358
" with show_code06_output:\n",
357359
" display.clear_output()\n",
358-
" print(f'icesat2.init()')\n",
359-
" # validate boolean entries to be in title case\n",
360-
" atl06_json = json.dumps(atl06_parms, indent=4)\n",
361-
" atl06_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl06_json)\n",
362-
" print('parms = ', atl06_json, sep='')\n",
363-
" print('gdf = icesat2.atl06p(parms)')\n",
360+
" code06_is_shown = not code06_is_shown\n",
361+
" if code06_is_shown:\n",
362+
" print(f'icesat2.init()')\n",
363+
" # validate boolean entries to be in title case\n",
364+
" atl06_json = json.dumps(atl06_parms, indent=4)\n",
365+
" atl06_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl06_json)\n",
366+
" print('parms = ', atl06_json, sep='')\n",
367+
" print('gdf = icesat2.atl06p(parms)')\n",
368+
" show_code06_button.description = \"Hide Code\"\n",
369+
" else:\n",
370+
" show_code06_button.description = \"Show Code\"\n",
371+
"\n",
364372
"\n",
365373
"# Download ATL06-SR data as geojson\n",
366374
"display.display(download_output)\n",
@@ -449,7 +457,7 @@
449457
"# display buttons\n",
450458
"display.display(run_button)\n",
451459
"display.display(SRwidgets.HBox([download_atl06_button, SRwidgets.file_format]))\n",
452-
"display.display(SRwidgets.HBox([show_code06_button, show_code06_output]))"
460+
"display.display(show_code06_button, show_code06_output)"
453461
]
454462
},
455463
{
@@ -639,17 +647,23 @@
639647
"m.add_selected_callback(click_handler)\n",
640648
"\n",
641649
"# show code action\n",
650+
"global code03_is_shown\n",
651+
"code03_is_shown = False\n",
642652
"def on_show_code03_clicked(b):\n",
643-
" global url_textbox, atl03_parms\n",
653+
" global url_textbox, atl03_parms, code03_is_shown\n",
644654
" with show_code03_output:\n",
645655
" display.clear_output()\n",
646-
" print(f'icesat2.init()')\n",
647-
" # validate boolean entries to be in title case\n",
648-
" atl03_json = json.dumps(atl03_parms, indent=4)\n",
649-
" atl03_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl03_json)\n",
650-
" print('parms = ', atl03_json, sep='')\n",
651-
" print('gdf = icesat2.atl03sp(parms)')\n",
652-
"\n",
656+
" code03_is_shown = not code03_is_shown\n",
657+
" if code03_is_shown:\n",
658+
" print(f'icesat2.init()')\n",
659+
" # validate boolean entries to be in title case\n",
660+
" atl03_json = json.dumps(atl03_parms, indent=4)\n",
661+
" atl03_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl03_json)\n",
662+
" print('parms = ', atl03_json, sep='')\n",
663+
" print('gdf = icesat2.atl03sp(parms)')\n",
664+
" show_code03_button.description = \"Hide Code\"\n",
665+
" else:\n",
666+
" show_code03_button.description = \"Show Code\"\n",
653667
"\n",
654668
"def on_atl03_download_clicked(e=None):\n",
655669
" download_file(atl03_rsps, SRwidgets.atl03_filename,\n",

0 commit comments

Comments
 (0)