Skip to content

Commit bb1220f

Browse files
enryHsayalaruano
andauthored
🎨 add basic vuegen demo to docs #64 (#65)
* 🎨 add vuegen demo to docs #64 * 🎨 add boolean for colab * 🐛 add missing import * 🐛 remove old references to platform in commented sections * 🎨 format for block uncommeting - might be good to have this as a parameter which is per default set to false? (open=False) * 🎨 Style(vuegen_case_study_earth_microbiome.ipynb): Update EMP example notebook with boolean for colab * 🎨 toogle streamlit app running in tutorial (especially for colab) * 📝 Docs: Add instructions to launch the streamlit app from colab on the two demo notebooks --------- Co-authored-by: Sebastián Ayala Ruano <[email protected]> Co-authored-by: sayalaruano <[email protected]>
1 parent 0d8c5f8 commit bb1220f

File tree

3 files changed

+98
-46
lines changed

3 files changed

+98
-46
lines changed

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<!-- https://myst-parser.readthedocs.io/en/latest/faq/index.html
44
#include-a-file-from-outside-the-docs-folder-like-readme-md -->
5+
56
```{include} ../README.md
67
:start-line: 0
78
:relative-docs: docs
@@ -18,6 +19,7 @@ vuegen_demo
1819
:maxdepth: 1
1920
:caption: Building a report
2021
22+
vuegen_basic_case_study
2123
vuegen_case_study_earth_microbiome
2224
example_report
2325
```

docs/vuegen_basic_case_study.ipynb

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@
5454
"source": [
5555
"### 0.1. Installing libraries and creating global variables for platform and working directory\n",
5656
"\n",
57-
"To run this notebook locally, you should create a virtual environment with the required libraries and set the `platform` variable to `local_notebook`. If you are running this notebook on Google Colab, set the `platform` variable to `colab`."
57+
"To run this notebook locally, you should create a virtual environment with the required libraries. If you are running this notebook on Google Colab, everything should be set."
5858
]
5959
},
6060
{
6161
"cell_type": "code",
6262
"execution_count": null,
63-
"metadata": {},
63+
"metadata": {
64+
"tags": [
65+
"hide-output"
66+
]
67+
},
6468
"outputs": [],
6569
"source": [
6670
"# Vuegen library \n",
@@ -69,11 +73,12 @@
6973
},
7074
{
7175
"cell_type": "code",
72-
"execution_count": null,
76+
"execution_count": 1,
7377
"metadata": {},
7478
"outputs": [],
7579
"source": [
76-
"platform = 'local_notebook' #@param ['colab', 'local_notebook'] {allow-input: true}"
80+
"import os\n",
81+
"IN_COLAB = \"COLAB_GPU\" in os.environ"
7782
]
7883
},
7984
{
@@ -83,11 +88,11 @@
8388
"outputs": [],
8489
"source": [
8590
"# Set working directory\n",
86-
"if platform == 'colab':\n",
91+
"if IN_COLAB:\n",
8792
" # Clone the repository in Colab\n",
8893
" !git clone --depth=1 https://github.com/Multiomics-Analytics-Group/vuegen.git\n",
8994
" base_output_dir = \"vuegen/docs/example_data/Basic_example_vuegen_demo_notebook/\"\n",
90-
"elif platform == 'local_notebook':\n",
95+
"else:\n",
9196
" # Output directory for local execution\n",
9297
" base_output_dir = \"./example_data/Basic_example_vuegen_demo_notebook/\""
9398
]
@@ -99,7 +104,7 @@
99104
"outputs": [],
100105
"source": [
101106
"# Optional library to launch a streamlit app from colab\n",
102-
"if platform == 'colab':\n",
107+
"if IN_COLAB:\n",
103108
" !npm install localtunnel"
104109
]
105110
},
@@ -112,7 +117,7 @@
112117
},
113118
{
114119
"cell_type": "code",
115-
"execution_count": 27,
120+
"execution_count": null,
116121
"metadata": {},
117122
"outputs": [],
118123
"source": [
@@ -122,7 +127,7 @@
122127
"from vuegen import report_generator\n",
123128
"from vuegen.utils import get_logger, load_yaml_config\n",
124129
"\n",
125-
"if platform == 'colab':\n",
130+
"if IN_COLAB:\n",
126131
" import urllib"
127132
]
128133
},
@@ -146,7 +151,9 @@
146151
"cell_type": "markdown",
147152
"metadata": {},
148153
"source": [
149-
"### 1.1. Streamlit report"
154+
"### 1.1. Streamlit report\n",
155+
"\n",
156+
"To launch the Streamlit web application from Colab, open the generated URL and copy the localtunnel entry point IP into the corresponding field on the opened page. Once submited, you will be redirected to your Streamlit web application."
150157
]
151158
},
152159
{
@@ -164,15 +171,30 @@
164171
"cell_type": "code",
165172
"execution_count": null,
166173
"metadata": {},
167-
"outputs": [],
174+
"outputs": [
175+
{
176+
"name": "stdout",
177+
"output_type": "stream",
178+
"text": [
179+
"Streamlit report not executed, set run_streamlit to True to run the report\n"
180+
]
181+
}
182+
],
168183
"source": [
184+
"run_streamlit = False\n",
185+
"# run_streamlit = True # uncomment line to run the streamlit report\n",
169186
"# Launch the Streamlit report depneding on the platform\n",
170-
"# if platform == \"local_notebook\":\n",
171-
"# !streamlit run streamlit_report/sections/report_manager.py\n",
172-
"# elif platform == \"colab\": # https://discuss.streamlit.io/t/how-to-launch-streamlit-app-from-google-colab-notebook/42399\n",
173-
"# print(\"Password/Enpoint IP for localtunnel is:\",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip(\"\\n\"))\n",
174-
"# !streamlit run streamlit_report/sections/report_manager.py --server.address=localhost &>/content/logs.txt &\n",
175-
"# !npx localtunnel --port 8501"
187+
"if not IN_COLAB and run_streamlit:\n",
188+
" !streamlit run streamlit_report/sections/report_manager.py\n",
189+
"elif run_streamlit:\n",
190+
" # see: https://discuss.streamlit.io/t/how-to-launch-streamlit-app-from-google-colab-notebook/42399\n",
191+
" print(\"Password/Enpoint IP for localtunnel is:\",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip(\"\\n\"))\n",
192+
" # Run the Streamlit app in the background\n",
193+
" !streamlit run streamlit_report/sections/report_manager.py --server.address=localhost &>/content/logs.txt &\n",
194+
" # Expose the Streamlit app on port 8501\n",
195+
" !npx localtunnel --port 8501 --subdomain vuegen-demo\n",
196+
"else:\n",
197+
" print(\"Streamlit report not executed, set run_streamlit to True to run the report\")"
176198
]
177199
},
178200
{
@@ -289,7 +311,9 @@
289311
"cell_type": "markdown",
290312
"metadata": {},
291313
"source": [
292-
"### 2.5. Stremlit report with the extended configuration file"
314+
"### 2.5. Stremlit report with the extended configuration file\n",
315+
"\n",
316+
"To launch the Streamlit web application from Colab, open the generated URL and copy the localtunnel entry point IP into the corresponding field on the opened page. Once submited, you will be redirected to your Streamlit web application."
293317
]
294318
},
295319
{
@@ -309,13 +333,20 @@
309333
"metadata": {},
310334
"outputs": [],
311335
"source": [
336+
"run_streamlit = False\n",
337+
"# run_streamlit = True # uncomment line to run the streamlit report\n",
312338
"# Launch the Streamlit report depneding on the platform\n",
313-
"#if platform == \"local_notebook\":\n",
314-
"# !streamlit run streamlit_report/sections/report_manager.py\n",
315-
"#elif platform == \"colab\":\n",
316-
"# print(\"Password/Enpoint IP for localtunnel is:\",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip(\"\\n\"))\n",
317-
"# !streamlit run streamlit_report/sections/report_manager.py --server.address=localhost &>/content/logs.txt &\n",
318-
"# !npx localtunnel --port 8501"
339+
"if not IN_COLAB and run_streamlit:\n",
340+
" !streamlit run streamlit_report/sections/report_manager.py\n",
341+
"elif run_streamlit:\n",
342+
" # see: https://discuss.streamlit.io/t/how-to-launch-streamlit-app-from-google-colab-notebook/42399\n",
343+
" print(\"Password/Enpoint IP for localtunnel is:\",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip(\"\\n\"))\n",
344+
" # Run the Streamlit app in the background\n",
345+
" !streamlit run streamlit_report/sections/report_manager.py --server.address=localhost &>/content/logs.txt &\n",
346+
" # Expose the Streamlit app on port 8501\n",
347+
" !npx localtunnel --port 8501 --subdomain vuegen-demo\n",
348+
"else:\n",
349+
" print(\"Streamlit report not executed, set run_streamlit to True to run the report\")"
319350
]
320351
},
321352
{
@@ -339,7 +370,7 @@
339370
],
340371
"metadata": {
341372
"kernelspec": {
342-
"display_name": "vuegen-IFxaxej_-py3.12",
373+
"display_name": "vuegen",
343374
"language": "python",
344375
"name": "python3"
345376
},
@@ -353,7 +384,7 @@
353384
"name": "python",
354385
"nbconvert_exporter": "python",
355386
"pygments_lexer": "ipython3",
356-
"version": "3.12.6"
387+
"version": "3.9.21"
357388
}
358389
},
359390
"nbformat": 4,

docs/vuegen_case_study_earth_microbiome.ipynb

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"source": [
6262
"### 0.1. Installing libraries and creating global variables for platform and working directory\n",
6363
"\n",
64-
"To run this notebook locally, you should create a virtual environment with the required libraries and set the `platform` variable to `local_notebook`. If you are running this notebook on Google Colab, set the `platform` variable to `colab`."
64+
"To run this notebook locally, you should create a virtual environment with the required libraries. If you are running this notebook on Google Colab, everything should be set."
6565
]
6666
},
6767
{
@@ -90,7 +90,8 @@
9090
"metadata": {},
9191
"outputs": [],
9292
"source": [
93-
"platform = 'local_notebook' #@param ['colab', 'local_notebook'] {allow-input: true}"
93+
"import os\n",
94+
"IN_COLAB = \"COLAB_GPU\" in os.environ"
9495
]
9596
},
9697
{
@@ -100,7 +101,7 @@
100101
"outputs": [],
101102
"source": [
102103
"# Optional library to launch a streamlit app from colab\n",
103-
"if platform == 'colab':\n",
104+
"if IN_COLAB:\n",
104105
" !npm install localtunnel"
105106
]
106107
},
@@ -148,7 +149,7 @@
148149
"from vuegen import report_generator\n",
149150
"from vuegen.utils import get_logger, load_yaml_config\n",
150151
"\n",
151-
"if platform == 'colab':\n",
152+
"if IN_COLAB:\n",
152153
" import urllib"
153154
]
154155
},
@@ -1368,7 +1369,9 @@
13681369
"cell_type": "markdown",
13691370
"metadata": {},
13701371
"source": [
1371-
"### 4.1. Streamlit report"
1372+
"### 4.1. Streamlit report\n",
1373+
"\n",
1374+
"To launch the Streamlit web application from Colab, open the generated URL and copy the localtunnel entry point IP into the corresponding field on the opened page. Once submited, you will be redirected to your Streamlit web application."
13721375
]
13731376
},
13741377
{
@@ -1388,13 +1391,20 @@
13881391
"metadata": {},
13891392
"outputs": [],
13901393
"source": [
1394+
"run_streamlit = False\n",
1395+
"# run_streamlit = True # uncomment line to run the streamlit report\n",
13911396
"# Launch the Streamlit report depneding on the platform\n",
1392-
"#if platform == \"local_notebook\":\n",
1393-
"# !streamlit run streamlit_report/sections/report_manager.py\n",
1394-
"#elif platform == \"colab\": # https://discuss.streamlit.io/t/how-to-launch-streamlit-app-from-google-colab-notebook/42399\n",
1395-
"# print(\"Password/Enpoint IP for localtunnel is:\",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip(\"\\n\"))\n",
1396-
"# !streamlit run streamlit_report/sections/report_manager.py --server.address=localhost &>/content/logs.txt &\n",
1397-
"# !npx localtunnel --port 8501"
1397+
"if not IN_COLAB and run_streamlit:\n",
1398+
" !streamlit run streamlit_report/sections/report_manager.py\n",
1399+
"elif run_streamlit:\n",
1400+
" # see: https://discuss.streamlit.io/t/how-to-launch-streamlit-app-from-google-colab-notebook/42399\n",
1401+
" print(\"Password/Enpoint IP for localtunnel is:\",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip(\"\\n\"))\n",
1402+
" # Run the Streamlit app in the background\n",
1403+
" !streamlit run streamlit_report/sections/report_manager.py --server.address=localhost &>/content/logs.txt &\n",
1404+
" # Expose the Streamlit app on port 8501\n",
1405+
" !npx localtunnel --port 8501 --subdomain vuegen-demo\n",
1406+
"else:\n",
1407+
" print(\"Streamlit report not executed, set run_streamlit to True to run the report\")"
13981408
]
13991409
},
14001410
{
@@ -1547,7 +1557,9 @@
15471557
"cell_type": "markdown",
15481558
"metadata": {},
15491559
"source": [
1550-
"### 5.5. Stremlit report with the extended configuration file"
1560+
"### 5.5. Stremlit report with the extended configuration file\n",
1561+
"\n",
1562+
"To launch the Streamlit web application from Colab, open the generated URL and copy the localtunnel entry point IP into the corresponding field on the opened page. Once submited, you will be redirected to your Streamlit web application."
15511563
]
15521564
},
15531565
{
@@ -1567,13 +1579,20 @@
15671579
"metadata": {},
15681580
"outputs": [],
15691581
"source": [
1582+
"run_streamlit = False\n",
1583+
"# run_streamlit = True # uncomment line to run the streamlit report\n",
15701584
"# Launch the Streamlit report depneding on the platform\n",
1571-
"#if platform == \"local_notebook\":\n",
1572-
"# !streamlit run streamlit_report/sections/report_manager.py\n",
1573-
"#elif platform == \"colab\":\n",
1574-
"# print(\"Password/Enpoint IP for localtunnel is:\",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip(\"\\n\"))\n",
1575-
"# !streamlit run streamlit_report/sections/report_manager.py --server.address=localhost &>/content/logs.txt &\n",
1576-
"# !npx localtunnel --port 8501"
1585+
"if not IN_COLAB and run_streamlit:\n",
1586+
" !streamlit run streamlit_report/sections/report_manager.py\n",
1587+
"elif run_streamlit:\n",
1588+
" # see: https://discuss.streamlit.io/t/how-to-launch-streamlit-app-from-google-colab-notebook/42399\n",
1589+
" print(\"Password/Enpoint IP for localtunnel is:\",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip(\"\\n\"))\n",
1590+
" # Run the Streamlit app in the background\n",
1591+
" !streamlit run streamlit_report/sections/report_manager.py --server.address=localhost &>/content/logs.txt &\n",
1592+
" # Expose the Streamlit app on port 8501\n",
1593+
" !npx localtunnel --port 8501 --subdomain vuegen-demo\n",
1594+
"else:\n",
1595+
" print(\"Streamlit report not executed, set run_streamlit to True to run the report\")"
15771596
]
15781597
},
15791598
{
@@ -1597,7 +1616,7 @@
15971616
],
15981617
"metadata": {
15991618
"kernelspec": {
1600-
"display_name": "vuegen-IFxaxej_-py3.12",
1619+
"display_name": "vuegen",
16011620
"language": "python",
16021621
"name": "python3"
16031622
},
@@ -1611,7 +1630,7 @@
16111630
"name": "python",
16121631
"nbconvert_exporter": "python",
16131632
"pygments_lexer": "ipython3",
1614-
"version": "3.12.6"
1633+
"version": "3.9.21"
16151634
}
16161635
},
16171636
"nbformat": 4,

0 commit comments

Comments
 (0)