Skip to content

Commit

Permalink
Merge pull request #68 from dominikl/jupyter_docker
Browse files Browse the repository at this point in the history
Jupyter docker
  • Loading branch information
jburel authored Jun 5, 2019
2 parents c2b464c + 0b7a993 commit 0c1d89f
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 0 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
^inst$
^java$
^CHANGELOG.md$
^jupyter$
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Alternatively: In R console run `install.packages("https://github.com/ome/rOMERO

See [Tips for Unix users](#tips-for-unix-users) section if you are running into difficulties.

### Docker / Jupyter

With [Docker](https://www.docker.com/) and [Jupyter](https://jupyter.org/) there is a quick and easy way to
get an R OMERO enviroment set up and running in your browser. Ideal to quickly try out some snippets. Go to
(jupyter)[jupyter] directory and see the instructions there.

## Usage

* Like any other R package load the package ```library(romero.gateway)```
Expand Down
36 changes: 36 additions & 0 deletions jupyter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM imagedata/jupyter-docker:0.9.0
MAINTAINER ome-devel@lists.openmicroscopy.org.uk

# The branch to build the romero.gateway from
ARG ROMERO_VERSION=
ARG ROMERO_BRANCH_USER=ome
ARG ROMERO_BRANCH=master
ARG INSTALL_SCRIPT_URL=https://raw.githubusercontent.com/ome/rOMERO-gateway/master/install.R

# R-kernel and R-OMERO prerequisites
ADD environment-r-omero.yml .setup/
RUN conda env update -n r-omero -q -f .setup/environment-r-omero.yml && \
/opt/conda/envs/r-omero/bin/Rscript -e "IRkernel::installspec(displayname='OMERO R')"

USER root
RUN mkdir /opt/romero /opt/omero && \
fix-permissions /opt/romero /opt/omero
# R requires these two packages at runtime
RUN apt-get install -y -q \
libxrender1 \
libsm6
USER $NB_UID

# build/install rOMERO
ENV _JAVA_OPTIONS="-Xss2560k -Xmx2g"
RUN cd /opt/romero && \
curl -sf $INSTALL_SCRIPT_URL --output install.R
RUN if [ -z ${ROMERO_VERSION} ]; then \
bash -c "source activate r-omero && Rscript /opt/romero/install.R --user=$ROMERO_BRANCH_USER --branch=$ROMERO_BRANCH --quiet"; else \
bash -c "source activate r-omero && Rscript /opt/romero/install.R --version=$ROMERO_VERSION --quiet"; fi

ENV OMERO_LIBS_DOWNLOAD=TRUE
RUN bash -c "source activate r-omero && echo \"library('romero.gateway')\" | R --no-save"

COPY --chown=1000:100 Get_Started.ipynb notebooks/

82 changes: 82 additions & 0 deletions jupyter/Get_Started.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load library and connect to an OMERO server"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"library(romero.gateway)\n",
"library(EBImage) # for displaying an image (also useful for image analysis!)\n",
"\n",
"# Connect to server\n",
"server <- OMEROServer(host = 'SERVER_NAME', username='USER_NAME', password='PASSWORD', port= as.integer(4064))\n",
"server <- connect(server)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Perform some tasks"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load an image\n",
"imageId <- IMAGE_ID # Replace with an actual image id\n",
"image <- loadObject(server, \"ImageData\", imageId)\n",
"pixels <- getPixelValues(image, 1, 1, 1)\n",
"\n",
"# Use EBImage to display it\n",
"ebimage <- EBImage::Image(data = pixels, colormode = 'Grayscale')\n",
"ebimage <- normalize(ebimage)\n",
"EBImage::display(ebimage)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Disconnect again"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"disconnect(server)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "OMERO R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
28 changes: 28 additions & 0 deletions jupyter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Jupyter server
==============

Spin up a Jupyter server with Docker:

CD into this directory and run:
```
docker build -t romero .
```
(this will build the romero.gateway from the current ome/master branch)

Run the docker image:
```
docker run -it -p 8888:8888 romero
```

Go to the respective URL in your browser and open the `Get_Started` notebook in `notebooks`,
or create a new 'OMERO R' notebook from scratch!

Notes:
- If you want to build a specific version or branch use:
```
docker build --build-arg ROMERO_VERSION=0.4.5 .
docker build --build-arg ROMERO_BRANCH_USER=ome --build-arg ROMERO_BRANCH=master .
```
- The Dockerfile uses the [install.R](../install.R) script from the master branch.
You can specify a different script with the `INSTALL_SCRIPT_URL` parameter.
25 changes: 25 additions & 0 deletions jupyter/environment-r-omero.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Install some common, useful R packages. These are
# not all strictly necessary for romero.gateway.
channels:
- bioconda
- conda-forge
- defaults
dependencies:
- bioconductor-ebimage
- openjdk=8.0.*
- r-assertthat
- r-base=3.5.*
- r-devtools
- r-git2r
- r-httr
- r-irdisplay
- r-irkernel
- r-jpeg
- r-repr
- r-rjava
- r-roxygen2
- r-testthat
- r-tidyverse
- r-xml2
- r-getpass
prefix: /opt/conda/envs/r-omero

0 comments on commit 0c1d89f

Please sign in to comment.