Skip to content

Commit 26b194c

Browse files
authored
Add Jupyter (#27)
* Started adding jupyter * Add docker-entrypoint.sh * Can start jupyter but permission issues * Finalize setu * Update README * Update versions * Update README
1 parent a84a0ff commit 26b194c

File tree

12 files changed

+152
-46
lines changed

12 files changed

+152
-46
lines changed

.env.example

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
# RStudio
2-
USER=rstudio
1+
# NLP Sandbox Notebooks image version
2+
IMAGE_VERSION=0.2.0
3+
4+
# User created when the container starts.
5+
# Those are the credentials to log in RStudio
6+
USERNAME=nlp
37
PASSWORD=changeme
48
USERID=1000
59
GROUPID=1000
610
ROOT=FALSE
711

8-
# Synapse
9-
SYNAPSE_TOKEN=yourtoken
12+
# Notebook IDE ("rstudio" or "jupyter")
13+
IDE=rstudio
14+
15+
# Port on the host that connects to the IDE
16+
HOST_RSTUDIO_PORT=8787
17+
HOST_JUPYTER_PORT=8888
1018

11-
# Port on the host that connects to RStudio
12-
HOST_PORT=80
19+
# Synapse settings
20+
SYNAPSE_TOKEN=
1321

14-
# User-specified settings made visible to RStudio (APP_*)
22+
# User-specified variables visible to RStudio (must start with "APP_")
1523
APP_NLPSANDBOX_SCHEMAS_VERSION=1.2.0

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ RUN install2.r --error renv \
2121
&& R -e "renv::restore(lockfile='/tmp/renv.lock')" \
2222
&& rm -rf /tmp/downloaded_packages/ /tmp/*.rds /tmp/renv.lock \
2323
&& R -e "extrafont::font_import(prompt=FALSE)"
24+
25+
WORKDIR /
26+
COPY docker-entrypoint.sh .
27+
RUN chmod +x docker-entrypoint.sh
28+
29+
ENTRYPOINT ["/docker-entrypoint.sh"]
30+
CMD ["rstudio"]
31+
# CMD ["jupyter"]

README.md

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,45 @@
1010

1111
## Introduction
1212

13-
This repository provides Rmd notebooks that enable you to use R and Python
14-
together to interact with the NLP Sandbox ecosystem. For example, use example
15-
notebooks included with this repository to perform analysis using data stored in
16-
a local or remote instance of the NLP Sandbox Data Node. See the Section
17-
[Notebooks](#Notebooks) below for the list of notebooks included with this
18-
repository.
13+
This repository provides a portable development environment that includes
14+
RStudio and Jupyter. This environment aims to support NLP Sandbox users who
15+
develop or apply tools that intereact with the NLP Sandbox ecosystem.
1916

20-
The Docker image [nlpsandbox/notebooks] offered by this project is based on the
21-
image [sagebionetworks/rstudio].
17+
For example, try the example notebooks included with this repository to perform
18+
analysis using data stored in a local or remote instance of the NLP Sandbox Data
19+
Node. See the Section [Notebooks](#Notebooks) for the list of example notebooks
20+
included with this repository.
21+
22+
The Docker image [nlpsandbox/notebooks] that comes with this project is based on
23+
the image [sagebionetworks/rstudio].
2224

2325
## Requirements
2426

25-
- [Docker Engine] >=19.03.0
27+
- [Docker Engine] >= 19.03.0
2628
- [Synapse.org] user account
2729

2830
## Specification
2931

30-
- Notebooks version: 0.1.0
32+
- Notebooks version: 0.2.0
3133
- NLP Sandbox schemas version: 1.2.0
34+
- RStudio version: 4.1.0
35+
- JupyterLab version: 3.2.1
3236

3337
## Notebooks
3438

35-
Rmd Notebook | Description
39+
Example notebooks for RStudio:
40+
41+
Notebook | Description
42+
-------- | -----------
43+
[notebook.Rmd](notebooks/rstudio/notebook.Rmd) | Default RStudio notebook.
44+
[r-and-python.Rmd](notebooks/rstudio/r-and-python.Rmd) | Shows how to use R and Python together.
45+
[data-node.Rmd](notebooks/rstudio/data-node.Rmd) | Interact with an NLP Sandbox Data Node instance.
46+
47+
Example notebooks for Jupiter:
48+
49+
Notebook | Description
3650
-------- | -----------
37-
[notebook.Rmd](notebooks/notebook.Rmd) | Default RStudio notebook.
38-
[r-and-python.Rmd](notebooks/r-and-python.Rmd) | Shows how to use R and Python together.
39-
[data-node.Rmd](notebooks/data-node.Rmd) | Interact with an NLP Sandbox Data Node instance.
51+
[hello-world.ipynb](notebooks/jupyter/hello-world.ipynb) | Hello World notebook.
4052

4153
> Important: Please make sure when you write your own notebooks that no
4254
> sensitive information ends up being publicly available. Please check with the
@@ -45,51 +57,61 @@ Rmd Notebook | Description
4557
4658
## Usage
4759

48-
Create and edit the configuration file.
60+
Create the configuration file.
4961

5062
cp .env.example .env
5163

52-
You can either pull the docker image [nlpsandbox/notebooks] or build it using
64+
Specify in the config file what IDE should be used.
65+
66+
# Notebook IDE ("rstudio" or "jupyter")
67+
IDE=rstudio
68+
69+
You can either pull the Docker image [nlpsandbox/notebooks] or build it using
5370
the information included in `docker-compose.yml`. To pull the image and start
54-
RStudio:
71+
the IDE:
5572

5673
docker compose pull
5774
docker compose up
5875

59-
If you want to build the image and start RStudio, for instance after customizing
60-
`Dockerfile`:
76+
If you want to build the image before starting the IDE, for instance after
77+
customizing `Dockerfile`:
6178

6279
docker compose up --build
6380

64-
RStudio is now available at http://localhost. On the login page, enter the
65-
default username (`rstudio`) and the password specified in `.env`.
81+
To access the IDE, open your browser and follow the instructions below.
6682

67-
In RStudio, open the RStudio project provided by this repository by clicking on
68-
the button `Project: (None)` > `Open Project...` on the top-right corner, then
69-
select the file `nlpsandbox/nlpsandbox.Rproj`. You should now be able to open
70-
and run the notebook `r-and-python.Rmd`. This will confirm that you can
71-
successfully use R and Python togehter.
83+
- RStudio: Navigate to http://localhost:8787
84+
- Jupyter: Navigate to the link displayed in the terminal when Jupyter started.
85+
You will need to replace the hostname by "localhost". E.g.
86+
http://localhost:8888/lab?token=4b08e8fc4469db3b4de1bb4d0ca20ef3684e5705bd193855
87+
88+
### Stop the IDE
7289

73-
To stop RStudio, enter `Ctrl+C` followed by `docker compose down`. If running
90+
To stop the IDE, enter `Ctrl+C` followed by `docker compose down`. If running
7491
in detached mode, you will only need to enter `docker compose down`.
7592

7693
Tips:
7794

7895
- Add `-d` or `--detach` as in `docker compose up -d` to run in the background.
7996
- If the command `docker compose` is missing, try `docker-compose`.
8097

81-
## Configuring the CI/CD workflow
98+
## Open the RStudio project
99+
100+
In RStudio, open the RStudio project provided by this repository by clicking on
101+
the button `Project: (None)` > `Open Project...` on the top-right corner, then
102+
select the file `nlpsandbox/nlpsandbox.Rproj`. You should now be able to open
103+
and run the notebook `r-and-python.Rmd`. This will confirm that you can
104+
successfully use R and Python togehter.
82105

83-
The [CI/CD workflow] of this repository performs the following actions:
106+
## Configuring the CI/CD workflow
84107

85-
- Generate HTML notebooks from R notebook and publishes them to GitHub Pages.
86-
- Build the Docker image [nlpsandbox/notebooks] and push it to Docker Hub.
108+
The [CI/CD workflow] of this repository builds the Docker image
109+
[nlpsandbox/notebooks] and pushes it to Docker Hub.
87110

88-
If you decided to fork this repository or use it as a template, you will need to
111+
If you decide to use this repository as a GitHub template, you will need to
89112
update the environment variables defined at the top of the [CI/CD workflow]. You
90-
also need to create the following [GitHub Secrets]:
113+
also need to create the following [GitHub Secrets].
91114

92-
- `RSTUDIO_PASSWORD`: "changeme"
93115
- `DOCKERHUB_USERNAME`: Your Docker Hub username.
94116
- `DOCKERHUB_TOKEN`: A personal access token (PAT) that has the permissions to
95117
push the image.

conda/nlpsandbox/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
challengeutils==4.0.1
2+
jupyterlab==3.2.1
23
nlpsandbox-client==4.0.0
34
pandas==1.2.4
45
synapseclient==2.3.1

docker-compose.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@ version: "3.8"
22

33
services:
44
rstudio:
5-
image: nlpsandbox/notebooks:0.1.0
5+
image: nlpsandbox/notebooks:${IMAGE_VERSION}
66
build:
77
context: .
8-
container_name: nlpsandbox-notebooks
9-
command: rstudio
108
env_file:
119
- .env
10+
environment:
11+
# Prevents the local $USER value to be picked up. Instead use the user
12+
# value defined in .env
13+
- USER=${USERNAME}
14+
container_name: nlpsandbox-notebooks
15+
command: ${IDE}
1216
volumes:
13-
- .:/home/rstudio/nlpsandbox:rw
17+
- .:/home/${USERNAME}/nlpsandbox:rw
1418
# networks:
1519
# - data-node
1620
ports:
17-
- "${HOST_PORT}:8787"
21+
- "${HOST_RSTUDIO_PORT}:8787"
22+
- "${HOST_JUPYTER_PORT}:8888"
1823

1924
# networks:
2025
# data-node:

docker-entrypoint.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [ "$1" = 'rstudio' ]; then
6+
# RStudio userconf.sh script runs RStudio as $USER
7+
exec /init
8+
elif [ "$1" = 'jupyter' ]; then
9+
# /init takes care of creating $USER. It also starts RStudio.
10+
exec /init gosu $USER /opt/miniconda/envs/nlpsandbox/bin/jupyter-lab \
11+
--notebook-dir /home/${USER}/nlpsandbox \
12+
--port=8888 \
13+
--no-browser \
14+
--ip=0.0.0.0
15+
fi
16+
17+
exec /init gosu $USER "$@"

notebooks/jupyter/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.ipynb_checkpoints/
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 3,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"Hello World\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"print('Hello World')"
18+
]
19+
}
20+
],
21+
"metadata": {
22+
"interpreter": {
23+
"hash": "93e7f2dcfb01f6655e7a9697237dee78452e308af71dd1cd67063cb7230fb558"
24+
},
25+
"kernelspec": {
26+
"display_name": "Python 3.9.4 64-bit ('phi-deidentifier': conda)",
27+
"name": "python3"
28+
},
29+
"language_info": {
30+
"codemirror_mode": {
31+
"name": "ipython",
32+
"version": 3
33+
},
34+
"file_extension": ".py",
35+
"mimetype": "text/x-python",
36+
"name": "python",
37+
"nbconvert_exporter": "python",
38+
"pygments_lexer": "ipython3",
39+
"version": "3.9.4"
40+
}
41+
},
42+
"nbformat": 4,
43+
"nbformat_minor": 5
44+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)