From 59882baf74867662e93339f2404908af601ed1ad Mon Sep 17 00:00:00 2001 From: Thomas Schaffter Date: Wed, 12 May 2021 20:08:46 -0700 Subject: [PATCH] Release 1.1.0 (#43) * Add reticulate to renv.lock * Rename example notebook * Add content to README * Add support for Synapse PAT (fixes #42) * Add documentation to render HTML doc * Remove reference to latex in README * Update README * Update conda env * Fix lint checks --- .env.example | 6 +- .github/dependabot.yml | 6 - .github/workflows/ci.yml | 2 +- .github/workflows/lock.yml | 2 +- CONTRIBUTING.md | 1 + Dockerfile | 2 +- README.md | 230 +++++++----------- .../environment.yaml | 2 +- .../requirements.txt | 0 docker-compose.yml | 3 +- notebooks/{notebook.Rmd => example.Rmd} | 55 ++++- renv.lock | 56 +++++ root/etc/cont-init.d/30-configure-user | 5 +- 13 files changed, 208 insertions(+), 162 deletions(-) create mode 100644 CONTRIBUTING.md rename conda/{sage => sage-bionetworks}/environment.yaml (82%) rename conda/{sage => sage-bionetworks}/requirements.txt (100%) rename notebooks/{notebook.Rmd => example.Rmd} (55%) diff --git a/.env.example b/.env.example index 7fbbbd1..9c7a0eb 100644 --- a/.env.example +++ b/.env.example @@ -1,14 +1,12 @@ # RStudio RSTUDIO_USER=rstudio -RSTUDIO_PASSWORD=yourpasswordhere +RSTUDIO_PASSWORD=yourpassword RSTUDIO_USERID=1000 RSTUDIO_GROUPID=1000 RSTUDIO_ROOT=FALSE # Synapse -#SYNAPSE_USERNAME=yourusername -#SYNAPSE_API_KEY=yourapikey # TODO replace by PAT -#SYNAPSE_PAT=yourtokenhere +SYNAPSE_TOKEN=yourtoken # Port on the host that connects to RStudio HOST_PORT=80 \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 54bf6bf..2c3218b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,21 +6,15 @@ updates: schedule: interval: "monthly" target-branch: "main" - reviewers: - - "tschaffter" - package-ecosystem: "github-actions" directory: "/" schedule: interval: "monthly" target-branch: "main" - reviewers: - - "tschaffter" - package-ecosystem: "pip" directory: "/conda/sage" schedule: interval: "monthly" target-branch: "main" - reviewers: - - "tschaffter" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 974d53c..664b3d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: args: Dockerfile - name: Check that packages in requirements.txt files are in asc order run: | - sort -f --check conda/sage/requirements.txt + sort -f --check conda/sage-bionetworks/requirements.txt test: needs: [lint] diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml index a1d5c74..13f1619 100644 --- a/.github/workflows/lock.yml +++ b/.github/workflows/lock.yml @@ -1,4 +1,4 @@ -name: 'Lock Threads' +name: Lock threads on: schedule: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5571c22 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +## TBA \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e32c4f0..c5bf508 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,7 +43,7 @@ RUN curl -fsSLO https://repo.anaconda.com/miniconda/Miniconda3-${miniconda3_vers # Create conda environments COPY conda /tmp/conda RUN conda init bash \ - && conda env create -f /tmp/conda/sage/environment.yaml \ + && conda env create -f /tmp/conda/sage-bionetworks/environment.yaml \ && rm -fr /tmp/conda \ # Fix libssl issue that affects conda env used with reticulate && cp /usr/lib/x86_64-linux-gnu/libssl.so.1.1 \ diff --git a/README.md b/README.md index 17a4fd1..90bf118 100644 --- a/README.md +++ b/README.md @@ -7,25 +7,18 @@ Docker image for analyses using RStudio and Python-Conda -## Motivations +## Overview -- Provides a versionized development environment (R, Python) -- Renders R notebooks to HTML and PDF programmatically (GH Action, etc.) +This project provides -## Specification - -- Extends the Docker image [rocker/rstudio] -- Behaves the same as [rocker/rstudio] and offer extra features (see below) -- Includes R packages to render HTML notebooks and use Python/conda (`reticulate`) -- Renders HTML and PDF notebooks from .Rmd files programmatically -- Comes with [Miniconda] installed -- Specifies the version of the R packages installed using `renv` -- Uses [GitHub Dependabot] to check Docker and pip dependencies +- a development environment where R and Python codes work together +- a portable development environment using Docker +- a versionized development environment ## Usage -1. Create and edit the file that contains the future environment variables. You - can initially start RStudio using this configuration as-is. +1. Create and edit the file that contains the environment variables. You can + initially start RStudio using this configuration as-is. cp .env.example .env @@ -36,117 +29,45 @@ Docker image for analyses using RStudio and Python-Conda RStudio is now available at http://localhost. On the login page, enter the default username (`rstudio`) and the password specified in `.env`. -To stop the API service, enter `Ctrl+C` followed by `docker-compose down`. If -running in detached mode, you will only need to enter `docker-compose down`. - -## Versioning - -### GitHub tags - -This repository uses [semantic versioning] to track the releases of this -project. This repository uses "non-moving" GitHub tags, that is, a tag will -always point to the same git commit once it has been created. - -### Docker tags - -The artifact published by this repository is a Docker image. The versions of the -image are aligned with the versions of [rocker/rstudio], not the versions of -Stubby or the GitHub tags of this repository. - -The table below describes the image tags available. - -| Tag name | Moving | Description -|---------------------------------|--------|------------ -| `latest` | Yes | Latest stable release. -| `edge` | Yes | Lastest commit made to the default branch. -| `` | Yes | Latest stable release for RStudio version ``. -| `.` | Yes | Latest stable release for RStudio version `.`. -| `..` | Yes | Latest stable release for RStudio version `..`. -| `..-` | No | Same as above but with the reference to the git commit. - -You should avoid using a moving tag like `latest` when deploying containers in -production, because this makes it hard to track which version of the image is -running and hard to roll back. - -## Contributing - -Thinking about contributing to this project? Get started by reading our -[Contributor Guide](CONTRIBUTING.md). - -## License - -[Apache License 2.0] - - - - + render + --> @@ -220,3 +167,6 @@ Run this command to convert the notebook to PDF (TBA) [semantic versioning]: https://semver.org/ [rocker/rstudio]: https://hub.docker.com/r/rocker/rstudio [Apache License 2.0]: https://github.com/tschaffter/rstudio/blob/main/LICENSE +[Sage Bionetworks]: https://sagebionetworks.org +[reticulate]: https://rstudio.github.io/reticulate +[tschaffter/rstudio]: https://hub.docker.com/repository/docker/tschaffter/rstudio diff --git a/conda/sage/environment.yaml b/conda/sage-bionetworks/environment.yaml similarity index 82% rename from conda/sage/environment.yaml rename to conda/sage-bionetworks/environment.yaml index 0ddb607..f895cf5 100644 --- a/conda/sage/environment.yaml +++ b/conda/sage-bionetworks/environment.yaml @@ -1,4 +1,4 @@ -name: sage +name: sage-bionetworks channels: - defaults dependencies: diff --git a/conda/sage/requirements.txt b/conda/sage-bionetworks/requirements.txt similarity index 100% rename from conda/sage/requirements.txt rename to conda/sage-bionetworks/requirements.txt diff --git a/docker-compose.yml b/docker-compose.yml index d41dc43..8437d11 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,8 +13,7 @@ services: - USERID=${RSTUDIO_USERID} - GROUPID=${RSTUDIO_GROUPID} - ROOT=${RSTUDIO_ROOT} - - SYNAPSE_USERNAME - - SYNAPSE_API_KEY + - SYNAPSE_TOKEN volumes: - .:/home/rstudio/awesome-project:rw ports: diff --git a/notebooks/notebook.Rmd b/notebooks/example.Rmd similarity index 55% rename from notebooks/notebook.Rmd rename to notebooks/example.Rmd index e0549a8..425d56d 100644 --- a/notebooks/notebook.Rmd +++ b/notebooks/example.Rmd @@ -1,8 +1,19 @@ --- -title: "R Notebook" -output: html_notebook +title: "Post Challenge Survey Analysis" +author: "Thomas Schaffter" +date: "`r Sys.Date()`" +output: + html_document: + df_print: paged + code_fold: hide + toc: yes + toc_float: yes + pdf_document: + toc: yes --- +# Test + This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code. Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Ctrl+Shift+Enter*. @@ -17,7 +28,45 @@ When you save the notebook, an HTML file containing the code and output will be The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike *Knit*, *Preview* does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed. +# List and activate Conda environments + +List the Conda environments + ```{r} library(reticulate) conda_list(conda = "auto") -``` \ No newline at end of file +``` + +Activate the environment `sage-bionetworks`: + +```{r} +use_condaenv("sage-bionetworks", required = TRUE) +``` + +# Use R and Python + +Define a variable in R: + +```{r} +a <- 1 +``` + +Access R objects in Python code blocks using the prefix `r.`: + +```{python} +r.a += 1 +b = 'hello-world' +``` + +Resume working with the variable `a` in R: + +```{r} +a +``` + +Access Python objects in R code blocks using the prefix `py$`: + +```{r} +py$b +``` + diff --git a/renv.lock b/renv.lock index b13680d..4f35da4 100644 --- a/renv.lock +++ b/renv.lock @@ -9,6 +9,20 @@ ] }, "Packages": { + "Matrix": { + "Package": "Matrix", + "Version": "1.3-2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "ff280503079ad8623d3c4b1519b24ea2" + }, + "Rcpp": { + "Package": "Rcpp", + "Version": "1.0.6", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "dbb5e436998a7eba5a9d682060533338" + }, "base64enc": { "Package": "base64enc", "Version": "0.1-3", @@ -51,6 +65,13 @@ "Repository": "RSPM", "Hash": "af2c2531e55df5cf230c4b5444fc973c" }, + "jsonlite": { + "Package": "jsonlite", + "Version": "1.7.2", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "98138e0994d41508c7a6b84a0600cfcb" + }, "knitr": { "Package": "knitr", "Version": "1.33", @@ -58,6 +79,13 @@ "Repository": "RSPM", "Hash": "0bc1b5da1b0eb07cd4b727e95e9ff0b8" }, + "lattice": { + "Package": "lattice", + "Version": "0.20-41", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "fbd9285028b0263d76d18c95ae51a53d" + }, "magrittr": { "Package": "magrittr", "Version": "2.0.1", @@ -79,6 +107,20 @@ "Repository": "RSPM", "Hash": "26fa77e707223e1ce042b2b5d09993dc" }, + "png": { + "Package": "png", + "Version": "0.1-7", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "03b7076c234cb3331288919983326c55" + }, + "rappdirs": { + "Package": "rappdirs", + "Version": "0.3.3", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "5e3c5dc0b071b21fa128676560dbe94d" + }, "renv": { "Package": "renv", "Version": "0.13.2", @@ -86,6 +128,13 @@ "Repository": "RSPM", "Hash": "079cb1f03ff972b30401ed05623cbe92" }, + "reticulate": { + "Package": "reticulate", + "Version": "1.20", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "30ab0ea8c8d3dd16a3fa06903449bbfb" + }, "rlang": { "Package": "rlang", "Version": "0.4.11", @@ -121,6 +170,13 @@ "Repository": "RSPM", "Hash": "25b572f764f3c19fef9aac33b5724f3d" }, + "withr": { + "Package": "withr", + "Version": "2.4.2", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "ad03909b44677f930fa156d47d7a3aeb" + }, "xfun": { "Package": "xfun", "Version": "0.22", diff --git a/root/etc/cont-init.d/30-configure-user b/root/etc/cont-init.d/30-configure-user index 1ea061c..09d02dd 100644 --- a/root/etc/cont-init.d/30-configure-user +++ b/root/etc/cont-init.d/30-configure-user @@ -9,12 +9,11 @@ BASHRC_FILENAME="/home/${USER}/.bashrc" usermod --shell /bin/bash ${USER} # Create Synapse Python client configuration file -if [[ ! -z ${SYNAPSE_USERNAME} && ! -z ${SYNAPSE_API_KEY} ]]; then +if [[ ! -z ${SYNAPSE_TOKEN} ]]; then if [ ! -f ${SYNAPSE_CONFIG_FILENAME} ]; then printf "%s\n" \ "[authentication]" \ - "username = ${SYNAPSE_USERNAME}" \ - "apikey = ${SYNAPSE_API_KEY}" | tee -a ${SYNAPSE_CONFIG_FILENAME} >/dev/null + "authtoken=${SYNAPSE_TOKEN}" | tee -a ${SYNAPSE_CONFIG_FILENAME} >/dev/null chown "${USER}:${USER}" ${SYNAPSE_CONFIG_FILENAME} chmod 600 ${SYNAPSE_CONFIG_FILENAME}