├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .img └── docker_R.001.jpeg ├── 00-initial-setup └── README.md ├── 01-intro-to-docker └── README.md ├── 02-dockerfile ├── Dockerfile ├── Hello_useR!2022.R └── README.md ├── 03-docker-cli ├── Dockerfile ├── Hello_useR!2022.R ├── README.md ├── docker-cli.sh └── docker-compose.yml ├── 04-docker-and-r ├── 01-intro-to-rocker │ └── README.md ├── 02-installing-r-packages │ ├── 02a-command-line │ │ ├── 01-docker-build.sh │ │ ├── 02-check.sh │ │ ├── Dockerfile │ │ └── README.md │ ├── 02b-using-mran │ │ ├── 01-docker-build.sh │ │ ├── 02-check.sh │ │ ├── Dockerfile │ │ └── README.md │ ├── 02c-using-renv-option-1 │ │ ├── 01-docker-build.sh │ │ ├── Dockerfile │ │ ├── README.md │ │ └── renv.lock │ ├── 02d-using-renv-option-2 │ │ ├── README.md │ │ ├── project_folder │ │ │ ├── .Renviron │ │ │ ├── docker │ │ │ │ ├── Dockerfile │ │ │ │ └── docker-build.sh │ │ │ ├── run-docker.sh │ │ │ └── script.R │ │ └── renv-cache │ │ │ └── .gitkeep │ └── README.md ├── 03-develop-in-docker │ ├── 01-docker-build.sh │ ├── 02-run-docker.sh │ ├── Dockerfile │ ├── README.md │ └── useR_2022 │ │ ├── test.R │ │ └── useR_2022.Rproj ├── 04-deploy-models-in-docker │ ├── 01-docker-build.sh │ ├── Dockerfile │ ├── README.md │ └── model │ │ ├── build-model.R │ │ ├── lm_model.rds │ │ ├── plumb-model.R │ │ └── predict.R ├── 05-deploy-shiny-in-docker │ ├── 01-docker-build.sh │ ├── Dockerfile │ ├── README.md │ ├── docker-compose.yml │ └── my_app │ │ └── app.R └── README.md ├── 05-dev-environments ├── 01-vscode-ide │ ├── .devcontainer │ │ ├── devcontainer.json │ │ └── docker-compose.yml │ ├── .lintr │ ├── .vscode │ │ ├── launch.json │ │ └── settings.json │ ├── 01-docker-build.sh │ ├── Dockerfile │ ├── README.md │ ├── docker-compose.yml │ ├── renv.lock │ └── test.R └── package.template │ ├── .Rbuildignore │ ├── DESCRIPTION │ ├── NAMESPACE │ ├── R │ └── functions.R │ ├── docker │ └── dev │ │ ├── build_docker.sh │ │ ├── dockerfile │ │ └── install_packages.R │ ├── man │ └── line_plot.Rd │ └── package.template.Rproj ├── 06-resources └── README.md ├── Introduction to Docker for R users.pdf └── README.md /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug, triage 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement, triage 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | .DS_Store 6 | .config 7 | .local -------------------------------------------------------------------------------- /.img/docker_R.001.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsangole/user2022-r-for-docker/1d0551b60970b6836182f3ef79a26ee58a86cb8c/.img/docker_R.001.jpeg -------------------------------------------------------------------------------- /00-initial-setup/README.md: -------------------------------------------------------------------------------- 1 | ## Setting up Docker 2 | 3 | 4 | A good place to get started on Docker is their own documentation at [Orientation & Setup](https://docs.docker.com/get-started/). 5 | 6 | ## Quick Start Guide 7 | 8 | - For Macs, download Docker Desktop [here](https://docs.docker.com/desktop/mac/install/). 9 | - For Windows, download Docker Desktop [here](https://docs.docker.com/desktop/windows/install/). 10 | - For Linux, download Docker Desktop [here](https://docs.docker.com/desktop/linux/install/). 11 | 12 | Once installed, open a command prompt or bash window, and try running: 13 | 14 | ```sh 15 | docker run -d -p 80:80 docker/getting-started sh; echo "Hello" 16 | ``` 17 | 18 | Docker should first download the image `docker/getting-started` and then run a container and print 'Hello' to the terminal. 19 | 20 | ```sh 21 | (base) ~ ❯❯❯ docker run -d -p 80:80 docker/getting-started sh; echo "Hello" 22 | 23 | 38a2d6190e0ece38940d9d38f30e172b8e0569da63a6e3d8460d61c6472371f4 24 | Hello 25 | (base) ~ ❯❯❯ 26 | ``` 27 | 28 | The alpha numeric printed is the container-id for the container spun up. 29 | 30 | ## Getting ready for the workshop 31 | 32 | - Ensure Docker Desktop is installed and running using the instructions above 33 | - Make a clone of this repository to your machine 34 | - Download a few useful images listed below to save time during the workshop 35 | 36 | ```sh 37 | docker pull rocker/r-ver:4.2.0 38 | docker pull rocker/rstudio:4.2.0 39 | docker pull rstudio/plumber 40 | ``` 41 | 42 | - Grab a cup of coffee -------------------------------------------------------------------------------- /01-intro-to-docker/README.md: -------------------------------------------------------------------------------- 1 | - what is docker 2 | - why use docker 3 | - examples of usage 4 | - what are images 5 | - what are containers 6 | - what are tags 7 | - where to find docker images 8 | - how to navigate dockerhub 9 | -------------------------------------------------------------------------------- /02-dockerfile/Dockerfile: -------------------------------------------------------------------------------- 1 | # See dockerfile commands reference: https://docs.docker.com/engine/reference/builder/ 2 | FROM rocker/r-ver:4.2.0 3 | 4 | LABEL maintainer="Your Name " \ 5 | info="useR!2022 Conference Docker for R Users Workshop" \ 6 | code="https://github.com/rsangole/user2022-r-for-docker" \ 7 | license="MIT" 8 | 9 | ARG message1="Welcome to the useR!2022 Conference!!!" 10 | 11 | ENV message2="Welcome to the Docker for R Users Workshop!!!" 12 | 13 | RUN mkdir scripts 14 | 15 | COPY *.R scripts/ 16 | 17 | RUN Rscript scripts/Hello_useR!2022.R 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /02-dockerfile/Hello_useR!2022.R: -------------------------------------------------------------------------------- 1 | print(Sys.getenv("message1")) 2 | print(Sys.getenv("message2")) -------------------------------------------------------------------------------- /02-dockerfile/README.md: -------------------------------------------------------------------------------- 1 | ### Dockerfile 2 | 3 | The [Dockerfile](https://docs.docker.com/engine/reference/builder/) is the image manifest. It enables the user to define the image "recipe" by using a list of instructions for the **Docker engine**. The Docker engine uses those instructions to execute during the build time of the image. That includes leveraging other images, running commands lines operation to install requirements and dependencies, copying files and scripts from the local machine to the image, etc. 4 | 5 | In the following example, we will use the Dockerfile to import an image with a preset R 4.2.0 environment and run an R script `Hello_useR!2022.R` that displays two environment variables: 6 | 7 | `Dockerfile` 8 | ``` Dockerfile 9 | # See dockerfile commands reference: https://docs.docker.com/engine/reference/builder/ 10 | FROM rocker/r-ver:4.2.0 11 | 12 | LABEL maintainer="Your Name " \ 13 | info="useR!2022 Conference Docker for R Users Workshop" \ 14 | code="https://github.com/rsangole/user2022-r-for-docker" \ 15 | license="MIT" 16 | 17 | ARG message1="Welcome to the useR!2022 Conference!!!" 18 | 19 | ENV message2="Welcome to the Docker for R Users Workshop!!!" 20 | 21 | RUN mkdir scripts 22 | 23 | COPY *.R scripts/ 24 | 25 | RUN Rscript scripts/Hello_useR!2022.R 26 | 27 | ``` 28 | 29 | The `Dockerfile` will copy the following R script and execute it during the build time of the Docker image. 30 | 31 | `Hello_useR!2022.R` 32 | ``` R 33 | print(Sys.getenv("message1")) 34 | print(Sys.getenv("message2")) 35 | ``` 36 | 37 | Before diving into the Dockerfile commands, let's use the `build` command to build the image and inspect its output: 38 | 39 | ``` shell 40 | docker build . --progress=plain -t user2022:hello.world 41 | ``` 42 | 43 | **Note:** Don't worry if you are not familiar with the Docker CLI commands. This will be covered in detail in the following sections. In the example above, we used the `progress` and `t` arguments to customize the build output and set the image name and tag as `user2022:hello.world`, respectively. 44 | 45 | You should expect the following output: 46 | ``` shell 47 | #1 [internal] load build definition from Dockerfile 48 | #1 sha256:d4b9d3e621a5bc9651436029854a9a14941d1e10b2f25e2c4efd744d6aa9a0dc 49 | #1 transferring dockerfile: 37B done 50 | #1 DONE 0.0s 51 | 52 | #2 [internal] load .dockerignore 53 | #2 sha256:97003bfaa735ac1b9470c27123753eabdbdd0a6dfcd959c23e02c56e40958dba 54 | #2 transferring context: 2B done 55 | #2 DONE 0.0s 56 | 57 | #3 [internal] load metadata for docker.io/rocker/r-ver:4.2.0 58 | #3 sha256:266598a71b086c88f019f9187a5aaf6a74b2f977672d5ce8e758812d17a390ed 59 | #3 DONE 2.0s 60 | 61 | #4 [1/4] FROM docker.io/rocker/r-ver:4.2.0@sha256:f32b3e9e353fa63092093f2ce590d819f56eac92f6f79e97906d4f2b0eee5ef3 62 | #4 sha256:b1078d2e76fd8b401815fcff9401dd53403e2d2b839fd517e253a83020bf4938 63 | #4 CACHED 64 | 65 | #6 [internal] load build context 66 | #6 sha256:b33a9a9621d92c268a5f993db3300ab0585be9cc8ce262e6c6a8532ff54f36fd 67 | #6 transferring context: 38B done 68 | #6 DONE 0.0s 69 | 70 | #5 [2/4] RUN mkdir scripts 71 | #5 sha256:42381d19d2196949ad566901d4d965b68fad42302db7e498b24e12075880e366 72 | #5 DONE 0.9s 73 | 74 | #7 [3/4] COPY *.R scripts/ 75 | #7 sha256:d910e253fed5a46d8cd1953d49f04d067dac0f10930829a21463e8895f3bd41f 76 | #7 DONE 0.0s 77 | 78 | #8 [4/4] RUN Rscript scripts/Hello_useR!2022.R 79 | #8 sha256:50b90ed2e01a57d96236779ccf486e863a1b02e9a174ffa4cdea8d66a560bfb6 80 | #8 0.636 [1] "Welcome to the useR!2022 Conference!!!" 81 | #8 0.636 [1] "Welcome to the Docker for R Users Workshop!!!" 82 | #8 DONE 0.7s 83 | 84 | #9 exporting to image 85 | #9 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00 86 | #9 exporting layers 0.0s done 87 | #9 writing image sha256:4b91ffed7e78fb18e38a88f723a20501382a7ecfeafbb2409478562d4fc32e80 done 88 | #9 naming to docker.io/library/user2022:hello.world done 89 | #9 DONE 0.1s 90 | ``` 91 | 92 | Let's now go step by step to understand the functionality of each one of the `Dockerfile` commands and map it with the outputs: 93 | 94 | - `FROM` - Defines the base image to use for the build of the following stages. A valid docker will always start with FROM instruction. In the case above, we imported the `rocker/r-ver:4.2.0` image - a Linux OS with R version 4.2.0 installed. You can see in the output that steps 3 and 4 releated to the import process of the `rocker` image. 95 | - `LABEL` - Enables to add information about the image to the image's metadata, such as authors, maintainers, license, etc. In this case we defined four labels - `maintainer`, `info`, `code`, and `license`. 96 | - `ARG` - Defines variables that can be passed to the image during the build time. This variable will be available only during the build time as an environment variable. While we define in the example above a default value for the message1 variable, we can modify it during the build time using the `build-arg` argument. 97 | - `ENV` - Sets the image environment variables. Those variables are kept on the image metadata and can be used during the run time as well. 98 | - `RUN` - Enables to execute of CLI commands on the image during the image build time. 99 | - `COPY` - Enables copying files from the local system to the image during the image build time 100 | 101 | 102 | Other common commands: 103 | - `EXPOSE` - Defines the port on the container to listen during run time. 104 | - `CMD` - Enables the execution of commands during the run time (unlike RUN, which executes during the build time). 105 | - `ENDRYPOINT` - Enables the execution of commands during the run time with arguments. 106 | - `VOLUME` - Sets a mount point inside the image which can be linked with external volume (e.g., local directory). 107 | - `WORKDIR` - Defines the working directory inside the image for any RUN, CMD, ENTRYPOINT, COPY, and ADD commands 108 | 109 | Reference - https://docs.docker.com/reference/ 110 | -------------------------------------------------------------------------------- /03-docker-cli/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/r-ver:4.2.0 2 | 3 | LABEL maintainer="Your Name " \ 4 | info="useR!2022 Conference Docker for R Users Workshop" \ 5 | code="https://github.com/rsangole/user2022-r-for-docker" \ 6 | license="MIT" 7 | 8 | ARG message1="Welcome to the useR!2022 Conference!!!" 9 | 10 | ENV message2="Welcome to the Docker for R Users Workshop!!!" 11 | 12 | RUN mkdir scripts 13 | 14 | COPY *.R scripts/ 15 | 16 | RUN Rscript scripts/Hello_useR!2022.R -------------------------------------------------------------------------------- /03-docker-cli/Hello_useR!2022.R: -------------------------------------------------------------------------------- 1 | print(Sys.getenv("message1")) 2 | print(Sys.getenv("message2")) -------------------------------------------------------------------------------- /03-docker-cli/README.md: -------------------------------------------------------------------------------- 1 | # Docker CLI 2 | 3 | * `docker build` 4 | * `docker run` 5 | * `docker ps` 6 | * `docker exec` 7 | * `docker image inspect` 8 | * `docker compose` 9 | * `docker-compose.yml` 10 | * `docker-compose up` 11 | * `docker-compose down` 12 | -------------------------------------------------------------------------------- /03-docker-cli/docker-cli.sh: -------------------------------------------------------------------------------- 1 | # docker build, docker image ls 2 | 3 | # Build an image from a Dockerfile. 4 | # More information: . 5 | 6 | # - Build a docker image using the Dockerfile in the current directory: 7 | docker build . 8 | docker image ls 9 | 10 | # What do we see? 11 | # How do we read the output? 12 | 13 | # - Build a docker image and tag it: 14 | # Shortcut: docker build -t 15 | # Tag Schema: {namespace}/{image_name}:{tag} 16 | # docker_for_r:v1.0 17 | # your_orgs_docker_hub.com/project_name/shiny_app:prod-v2.0.5 18 | docker build --tag docker_for_r/simple:test . 19 | 20 | # - Build a docker image using a specific Dockerfile: 21 | docker build --file Dockerfile -t docker_for_r/simple:test . 22 | 23 | # docker image 24 | # Manage Docker images. 25 | 26 | # - List local Docker images: 27 | docker image ls 28 | 29 | # - Delete unused local Docker images: 30 | docker image prune 31 | 32 | docker image ls | grep docker_for_r 33 | 34 | docker image inspect docker_for_r/simple:test 35 | 36 | # docker run 37 | # Run a command in a new Docker container. 38 | 39 | # - Run command in a new container from a tagged image: 40 | # docker run image:tag command 41 | docker run docker_for_r/simple:test echo "Hello" 42 | 43 | # - Run command in a one-off container in interactive mode and pseudo-TTY: 44 | # docker run --rm -it image command 45 | docker run --rm -it docker_for_r/simple:test bash 46 | 47 | # - Run command in a new container in background and display its ID: 48 | # docker run -d image command 49 | docker run -d rocker/rstudio:4.2.0 50 | docker ps 51 | docker stop 193fb8a5c41b 52 | 53 | # - Run command in a new container with passed environment variables: 54 | # docker run -e 'variable=value' -e variable image command 55 | docker run -e 'NEW_VAR=3.14' --rm -it docker_for_r/simple:test bash 56 | 57 | # - Run command in a new container with bind mounted volumes: 58 | # docker run -v path/to/host_path:path/to/container_path image command 59 | docker run \ 60 | --rm \ 61 | -it \ 62 | -v /Users/rahul/github/github.com/user2022-r-for-docker/03-docker-cli:/home/work/ \ 63 | docker_for_r/simple:test \ 64 | bash 65 | 66 | # - Run command in a new container with published ports: 67 | # docker run -p host_port:container_port image command 68 | docker run \ 69 | -p 8787:8787 \ 70 | -e PASSWORD=user2022 \ 71 | rocker/rstudio:4.2.0 72 | 73 | # docker ps 74 | # List Docker containers. 75 | 76 | # - List currently running docker containers: 77 | docker ps 78 | 79 | # - List all docker containers (running and stopped): 80 | docker ps --all 81 | 82 | # docker exec 83 | # Execute a command on an already running Docker container. 84 | docker run \ 85 | -d \ 86 | -p 8787:8787 \ 87 | -e DISABLE_AUTH=true \ 88 | -e FOO=bar \ 89 | --name goblue \ 90 | rocker/rstudio:4.2.0 91 | docker ps 92 | docker exec -it goblue bash 93 | docker stop goblue 94 | 95 | # docker compose 96 | # Run and manage multi container docker applications. 97 | 98 | # Create and start all containers using a `docker-compose.yml` file from the current directory: 99 | docker-compose up 100 | 101 | # - List all running containers: 102 | docker-compose ps 103 | 104 | # - Create and start all containers in the background using a `docker-compose.yml` file from the current directory: 105 | docker-compose up -d 106 | 107 | # - Stop all running containers: 108 | docker-compose stop 109 | -------------------------------------------------------------------------------- /03-docker-cli/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.9" 2 | services: 3 | my_rstudio: 4 | image: rocker/rstudio:4.2.0 5 | ports: 6 | - "8787:8787" 7 | environment: 8 | DISABLE_AUTH: "true" 9 | NEW_VAR: "foo" 10 | volumes: 11 | - type: "bind" 12 | source: "/Users/rahul/github/github.com/user2022-r-for-docker/03-docker-cli" 13 | target: "/home/rstudio" -------------------------------------------------------------------------------- /04-docker-and-r/01-intro-to-rocker/README.md: -------------------------------------------------------------------------------- 1 | # The Rocker project 2 | 3 | **What is it?** 4 | 5 | This Rocker Project has a list of easy to use Docker images for various needs for R developers. 6 | 7 | **Why use it?** 8 | 9 | 1. The fastest way for new R users to get up & running in Docker 10 | 2. Plethora of Docker images to choose from for your usecase: Just R, R with RStudio, Images for Shiny, Images for Machine Learning, Images with GPU support 11 | 3. Well maintained version-tagged repository for a large number of R versions that _just work_ 12 | 13 | **Where can I learn more?** 14 | 15 | - [List of Images](https://www.rocker-project.org/images/) 16 | - [The Rocker Project](https://www.rocker-project.org/) 17 | 18 | --- 19 | 20 | # An Example 21 | 22 | Let's try out a basic image from the Rocker project. Let's pull a basic simple image containing R version 4.2.0. 23 | 24 | First, pull the image. 25 | 26 | ```sh 27 | docker pull rocker/r-ver:4.2.0 28 | ``` 29 | 30 | Second, read the *Dockerfile* [here](https://hub.docker.com/layers/r-ver/rocker/r-ver/4.2.0/images/sha256-a5cff75569e3fdae2ce1aa87516494801ba35b022c4adaeb2a33d1ee80319697?context=explore). 31 | 32 | Now, try running R with the image. Recall, the command follows the structure `docker run {arguments} {docker-image-name} {command-to-execute}`. 33 | 34 | ```sh 35 | docker run -it --rm rocker/r-ver:4.2.0 R 36 | ``` 37 | 38 | This should open a working R terminal in an interactive (`-it`) one-off container (`--rm`). 39 | 40 | To finish, use `q()`, which will exit the R terminal and close the active container. -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02a-command-line/01-docker-build.sh: -------------------------------------------------------------------------------- 1 | docker build . -t docker_for_r/package_example_simple:v1.0 -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02a-command-line/02-check.sh: -------------------------------------------------------------------------------- 1 | docker run --rm docker_for_r/package_example_simple:v1.0 Rscript -e 'packageVersion("cli"); packageVersion("txtplot")' -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02a-command-line/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/r-ver:4.2.0 2 | 3 | LABEL purpose="Simple example for a standard R package install or usage of install2.r" 4 | 5 | # Example of a conventional `install.packages()` approach 6 | RUN Rscript -e "install.packages('cli')" 7 | 8 | # Example of `install2.r` 9 | RUN install2.r \ 10 | --error \ 11 | txtplot -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02a-command-line/README.md: -------------------------------------------------------------------------------- 1 | # Command Line Install 2 | 3 | This example shows you how to install R packages using a "command line" approach, which is typically how you install R packages in R today. 4 | 5 | In the `Dockerfile`, you'll see two ways packages are installed: 6 | 7 | 1. using `install.packages` with `Rscript` 8 | 2. using a [littler](https://github.com/eddelbuettel/littler) script `install2.r 9 | 10 | # Instructions 11 | 12 | 1. Open and read the `Dockerfile` 13 | 2. Read `01-docker-build.sh`. Build the docker image by `./01-docker-build.sh` in your terminal 14 | 3. Read `02-check.sh`. Run it in your terminal using `./02-check.sh` to print the package versions. -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02b-using-mran/01-docker-build.sh: -------------------------------------------------------------------------------- 1 | docker build . -t docker_for_r/package_example_mran:v1.0 -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02b-using-mran/02-check.sh: -------------------------------------------------------------------------------- 1 | docker run --rm docker_for_r/package_example_mran:v1.0 Rscript -e 'packageVersion("cli"); packageVersion("txtplot")' -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02b-using-mran/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/r-ver:4.2.0 2 | 3 | LABEL purpose="Example of using MRAN repo" 4 | 5 | ENV MRAN_BUILD_DATE=2021-01-01 6 | 7 | # Example of a conventional `install.packages()` approach 8 | RUN Rscript -e "install.packages('cli', repos = 'https://cran.microsoft.com/snapshot/${MRAN_BUILD_DATE}')" 9 | 10 | # Example of `install2.r` 11 | RUN install2.r \ 12 | -r https://cran.microsoft.com/snapshot/${MRAN_BUILD_DATE} \ 13 | --error \ 14 | txtplot -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02b-using-mran/README.md: -------------------------------------------------------------------------------- 1 | # Command Line Install 2 | 3 | This example shows you how to install R packages using the [MRAN](https://mran.microsoft.com) repository. 4 | 5 | # Instructions 6 | 7 | 1. Open and read the `Dockerfile` 8 | 2. Read `01-docker-build.sh`. Build the docker image by `./01-docker-build.sh` in your terminal 9 | 3. Read `02-check.sh`. Run it in your terminal using `./02-check.sh` to print the package versions. 10 | 11 | We're using an older `MRAN_BUILD_DATE` of '2021-01-01'. Compare the versions of `{cli}` and `{txtplot}` to what we saw in example `02a`. -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02c-using-renv-option-1/01-docker-build.sh: -------------------------------------------------------------------------------- 1 | docker build . -t docker_for_r/package_example_renv_1:v1.0 -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02c-using-renv-option-1/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/r-ver:4.2.0 2 | 3 | LABEL purpose="Example of {renv}: Install packages when Docker image is built." 4 | 5 | ENV RENV_VERSION 0.15.5 6 | RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))" 7 | RUN R -e "remotes::install_github('rstudio/renv@${RENV_VERSION}')" 8 | 9 | WORKDIR /renv 10 | COPY renv.lock renv.lock 11 | 12 | RUN R -e "renv::restore()" 13 | -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02c-using-renv-option-1/README.md: -------------------------------------------------------------------------------- 1 | 2 | # `renv` Install - Install packages when Docker image is built 3 | 4 | 5 | # Instructions 6 | 7 | 1. Open and read the `Dockerfile`. Note how `renv` is installed first, and then the `renv.lock` file is copied to the image, and then the packages installed. 8 | 2. Review the `renv.lock` file. This defines which packages will be installed. 9 | 3. Read `01-docker-build.sh`. Build the docker image by `./01-docker-build.sh` in your terminal. This will build a new image called `docker_for_r/package_example_renv_1:v1.0`. 10 | 4. Read `02-check.sh`. Run it in your terminal using `./02-check.sh` to print the package versions. 11 | 5. Let's peek into the docker image further. Run `docker run --rm -it docker_for_r/package_example_renv_1:v1.0 bash` to start a container & open a bash terminal. 12 | 6. Answer these questions: 13 | 1. What's the current working directory? Why? 14 | 2. Can you find the `renv.lock` file? 15 | 3. Where are the packages we installed using `renv::restore`? _Hint: Look under ‘/usr/local/lib/R/site-library'` -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02c-using-renv-option-1/renv.lock: -------------------------------------------------------------------------------- 1 | { 2 | "R": { 3 | "Version": "4.2.0", 4 | "Repositories": [ 5 | { 6 | "Name": "CRAN", 7 | "URL": "https://cloud.r-project.org" 8 | } 9 | ] 10 | }, 11 | "Packages": { 12 | "R6": { 13 | "Package": "R6", 14 | "Version": "2.5.1", 15 | "Source": "Repository" 16 | }, 17 | "box": { 18 | "Package": "box", 19 | "Version": "1.1.2", 20 | "Source": "Repository" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/README.md: -------------------------------------------------------------------------------- 1 | # `renv` Install - Install packages when Docker container is run 2 | 3 | This approach uses a local shared cache can highly speed up the Docker build process across all Docker builds. This tutorial is a bit more involved and requires more orchestration than the others. 4 | 5 | The `project_folder` should be thought of as your project's working folder. This would be where you save your project scripts in a real world project. The `renv-cache` folder will simulate a location on disk where the common `renv` cache will be stored. 6 | 7 | # Instructions 8 | 9 | 1. Open and read the `Dockerfile`. Note how we do _not_ use `renv::restore` in this image. We _do not_ install the packages within the Docker image. 10 | 2. Read `project_folder/docker/docker-build.sh`. 11 | 1. In your terminal, change directories to `docker` using `cd project_folder/docker`. 12 | 2. Build the docker image by `./01-docker-build.sh`. 13 | 3. This will build a new image called `docker_for_r/package_example_renv_2:v1.0`. 14 | 3. Open `run-docker.sh` in your local editor. 15 | 1. You need to set two paths customized to your machine. 16 | 1. Set `YOUR_LOCAL_RENV_CACHE_PATH` to where `renv-cache` resides 17 | 2. Set `YOUR_LOCAL_PROJECT_FOLDER` to where `project_folder` resides 18 | 2. The `docker run` command will mount two volumes to your container: 19 | 1. `YOUR_LOCAL_RENV_CACHE_PATH` will mount to `/renv/cache` 20 | 2. `YOUR_LOCAL_PROJECT_FOLDER` will mount to `/home/work` 21 | 4. Review the project_folder/.Renviron` file. Notice that we set an environment variable which tells `{renv}` where it should find the package cache. 22 | 5. In your terminal, change into `project_folder/` and run the script using `./run-docker.sh`. 23 | 1. This will start a new container, open bash into the `/home/work` directory 24 | 2. Confirm using `pwd` 25 | 3. Run `ls` to see that the directory contents are now exposed to the container 26 | 4. Run `ls /renv/cache/`. It'll be empty right now. 27 | 6. Run `R`. 28 | 1. Confirm the renv cache location using: `Sys.getenv('RENV_PATHS_CACHE')` 29 | 2. Run `renv::init()` to initialize the project. `{renv}` will check the project folder, find all packages being used and create a `renv.lock` file with the packages. Since `script.R` references `data.table`, it'll be used in the `renv.lock` file, as well as installed in our cache location. Let's confirm this. 30 | 3. Run `q()` to exit R. 31 | 4. Run `ls /renv/cache/v5/R-4.2/x86_64-pc-linux-gnu/`. You'll see `data.table` present. 32 | 5. Since this folder is actually mounted from your local machine, let's confirm it outside the docker container. Open `Finder` or `Explorer`, head to the cache folder and confirm this for yourself. 33 | 6. Open `R` in your container again. Try installing a new package `renv::install("cli")`. 34 | 7. Peek into the renv cache folder again. What do you see? -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/project_folder/.Renviron: -------------------------------------------------------------------------------- 1 | RENV_PATHS_CACHE=/renv/cache -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/project_folder/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/r-ver:4.2.0 2 | 3 | LABEL purpose="Example of {renv}: Install packages when Docker image is built." 4 | 5 | ENV RENV_VERSION 0.15.5 6 | RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))" 7 | RUN R -e "remotes::install_github('rstudio/renv@${RENV_VERSION}')" 8 | 9 | RUN mkdir -p /renv/cache 10 | 11 | WORKDIR /home/work -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/project_folder/docker/docker-build.sh: -------------------------------------------------------------------------------- 1 | docker build . -t docker_for_r/package_example_renv_2:v1.0 -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/project_folder/run-docker.sh: -------------------------------------------------------------------------------- 1 | YOUR_LOCAL_RENV_CACHE_PATH="/Users/rahul/github/github.com/user2022-r-for-docker/04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/renv-cache" 2 | YOUR_LOCAL_PROJECT_FOLDER="/Users/rahul/github/github.com/user2022-r-for-docker/04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/project_folder" 3 | docker run \ 4 | --rm \ 5 | --volume $YOUR_LOCAL_RENV_CACHE_PATH:/renv/cache \ 6 | --volume $YOUR_LOCAL_PROJECT_FOLDER:/home/work \ 7 | -it \ 8 | docker_for_r/package_example_renv_2:v1.0 \ 9 | bash -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/project_folder/script.R: -------------------------------------------------------------------------------- 1 | library(data.table) 2 | 3 | dat <- as.data.table(mtcars) 4 | 5 | dat[] -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/renv-cache/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsangole/user2022-r-for-docker/1d0551b60970b6836182f3ef79a26ee58a86cb8c/04-docker-and-r/02-installing-r-packages/02d-using-renv-option-2/renv-cache/.gitkeep -------------------------------------------------------------------------------- /04-docker-and-r/02-installing-r-packages/README.md: -------------------------------------------------------------------------------- 1 | # Installing R Packages 2 | 3 | There are a couple of ways we can install R packages in a Docker image, each with their pros and cons. Let's explore all of them in this section. 4 | 5 | Method | Details | Pros | Cons 6 | --------------------|--------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------- 7 | `install2.r` | Install R packages using a [littler](https://github.com/eddelbuettel/littler/blob/master/inst/examples/install2.r) script from CRAN. |
  • Easy to use in `RUN` commands.
  • Well [documented](https://eddelbuettel.github.io/littler/)
|
  • Requires `{littler}` pre-installed.
  • Default CRAN repo does not ensure full reproducibility.
  • Packages are compiled from sources - high Docker build time
8 | MRAN | Install R packages from [MRAN repository](https://mran.microsoft.com). |
  • MRAN date-lock ensure full reproducibility at any time in the future
  • No dependencies on other R packages
|
  • Depend on Microsoft keeping MRAN alive
  • Can't lock down specific versions of R package
  • Packages are compiled from sources - high Docker build time
9 | [`{renv}`](https://rstudio.github.io/renv/index.html) Approach 1 | Install packages when Docker image is built. |
  • `{renv}` is an easy to use dependency management tool with a human-readable `renv.lock` file.
  • Ensures full reproduciblity. Locks package versions.
  • Once image is built, no external dependencies.
  • Binaries are prefered, reducing Docker build times significantly
  • Deployment to CI/CD frameworks is easier
|
  • Modifications to `{renv}` will require rebuilding the image.
10 | [`{renv}`](https://rstudio.github.io/renv/index.html) Approach 2 | Install packages when Docker container is run. |
  • Using a local shared cache can _highly speed up_ the Docker build process across all Docker builds
  • Binaries are prefered, reducing Docker build times significantly
|
  • Requires you to modify how containers are created
  • Requires a bit of extra orchestration in how containers are launched
  • Deployment in CI/CD frameworks requires extra orchestration
11 | 12 | 13 | [1] Useful reading for `{renv}` with Docker - [link](https://rstudio.github.io/renv/articles/docker.html) 14 | -------------------------------------------------------------------------------- /04-docker-and-r/03-develop-in-docker/01-docker-build.sh: -------------------------------------------------------------------------------- 1 | docker build . -t docker_for_r/rstudio:v1.0 -------------------------------------------------------------------------------- /04-docker-and-r/03-develop-in-docker/02-run-docker.sh: -------------------------------------------------------------------------------- 1 | YOUR_LOCAL_PROJECT_FOLDER="/Users/rahul/github/github.com/user2022-r-for-docker/04-docker-and-r/03-develop-in-docker/" 2 | 3 | docker run \ 4 | --rm \ 5 | -it \ 6 | -p 8787:8787 \ 7 | -e DISABLE_AUTH="true" \ 8 | -v $YOUR_LOCAL_PROJECT_FOLDER:/home/rstudio \ 9 | docker_for_r/rstudio:v1.0 -------------------------------------------------------------------------------- /04-docker-and-r/03-develop-in-docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/rstudio:4.2.0 2 | 3 | LABEL purpose="Example of developing in RStudio IDE" 4 | 5 | ENV MRAN_BUILD_DATE=2022-06-18 6 | 7 | RUN install2.r \ 8 | -r https://cran.microsoft.com/snapshot/${MRAN_BUILD_DATE} \ 9 | --error \ 10 | data.table 11 | 12 | EXPOSE 8787 -------------------------------------------------------------------------------- /04-docker-and-r/03-develop-in-docker/README.md: -------------------------------------------------------------------------------- 1 | # Develop in RStudio IDE 2 | 3 | This is an example of how to use the RStudio IDE in a Docker container to develop your project. 4 | 5 | # Instructions 6 | 7 | 1. Open and read the `Dockerfile`. 8 | 1. Note that we're now using a different base image from before. 9 | 2. `rocker/rstudio:4.2.0` is a base image which has RStudio pre-installed, perfect to quickly get started. 10 | 2. Read and execute `01-docker-build.sh` by running `./01-docker-build.sh` in your terminal. 11 | 2. This will build a new image called `docker_for_r/rstudio:v1.0`. 12 | 3. Open `02-run-docker.sh` in your local editor. 13 | 1. You need to set one path customized to your machine. 14 | 1. Set `YOUR_LOCAL_PROJECT_FOLDER` to where this folder resides. 15 | 2. The `docker run` command will mount the volume to your container, along with setting a few more settings: 16 | 1. `YOUR_LOCAL_PROJECT_FOLDER` will mount to `/home/rstudio` which is the default working folder for RStudio IDE. 17 | 2. `-p 8787:8787` maps an 8787 port from within the container to 8787 on your local machine. This is where RStudio will serve itself to us. 18 | 3. `-e DISABLE_AUTH="true"` avoids a login screen. If absent, a unique password will be offered to you in the terminal which you'll have to enter manually. 19 | 4. In your terminal, run the script using `./02-run-docker.sh`. 20 | 1. You'll see some verbiage on the terminal which will end with a line like `[services.d] done.` 21 | 5. Open your browser to http://localhost:8787 22 | 1. You should see the contents of `$YOUR_LOCAL_PROJECT_FOLDER` 23 | 2. Click and open the `useR_2022` R Project as you'd normally do 24 | 3. Execute the contents of `test.R`. A CSV file will be written back into the folder. 25 | 4. Confirm you're able to access the CSV file from outside the container using Finder or File Explorer. 26 | 6. Once you're done, you can stop the container by `control+c` in the terminal window. -------------------------------------------------------------------------------- /04-docker-and-r/03-develop-in-docker/useR_2022/test.R: -------------------------------------------------------------------------------- 1 | library(data.table) 2 | 3 | dt <- as.data.table(iris) 4 | 5 | dt[] 6 | 7 | dt |> 8 | fwrite("/home/rstudio/useR_2022/dt.csv") 9 | -------------------------------------------------------------------------------- /04-docker-and-r/03-develop-in-docker/useR_2022/useR_2022.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | -------------------------------------------------------------------------------- /04-docker-and-r/04-deploy-models-in-docker/01-docker-build.sh: -------------------------------------------------------------------------------- 1 | docker build . -t docker_for_r/model_deployment:v1.0 -------------------------------------------------------------------------------- /04-docker-and-r/04-deploy-models-in-docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rstudio/plumber 2 | 3 | LABEL purpose="Example of model deployment in Docker" 4 | 5 | WORKDIR /plumber/ 6 | COPY model/lm_model.rds lm_model.rds 7 | COPY model/plumb-model.R plumb-model.R 8 | COPY model/predict.R predict.R 9 | 10 | EXPOSE 8000 11 | 12 | ENTRYPOINT ["Rscript", "-e", "source('plumb-model.R')"] -------------------------------------------------------------------------------- /04-docker-and-r/04-deploy-models-in-docker/README.md: -------------------------------------------------------------------------------- 1 | # Deploy Predictive Model 2 | 3 | This is an example of how we can deploy a predictive model in Docker using the `{plumber}` API. A model file is embedded in the Docker image along with instructions (using `{plumber}`) on how the Docker container should handle requests to predict new data. 4 | 5 | The `model/` folder holds the scripts for creation and execution model: 6 | 7 | - `build-model.R` builds a simple linear regression model on the `mtcars` dataset. We're predicting `mpg ~ cyl + disp + hp`. The script then saves `lm_model.rds` to be used later. 8 | - `plumb-model.R` and `predict.R` are files to be used when the Docker container will be run 9 | 10 | # Instructions 11 | 12 | 1. Open and read the `Dockerfile`. 13 | 1. Note that we're now using a different base image here - `rstudio/plumber`. This is an image already configured with the `{plumber}` package. While we could start with our previous `rocker/r-ver` or `rocker/rstudio` images, the build for `{plumber}` takes quite a while. 14 | 2. We create a directory `/plumber/` in the image, and copy over the needed files from `model/` into it 15 | 3. Finally, we source the `plumb-model.R` file which serves the API over the port 8000. 16 | 2. Execute `01-docker-build.sh` by running `./01-docker-build.sh` in your terminal. This will build a new image called `docker_for_r/model_deployment:v1.0`. 17 | 3. Once built, in your terminal, run `docker run -p 8000:8000 docker_for_r/model_deployment:v1.0`. You should see outputs like: 18 | ``` 19 | (base) ❯❯❯ docker run -p 8000:8000 docker_for_r/model_deployment:v1 20 | Running plumb-model.R 21 | Running plumber API at http://0.0.0.0:8000 22 | Running swagger Docs at http://127.0.0.1:8000/__docs__/ 23 | ``` 24 | 4. Open your browser to http://127.0.0.1:8000/__docs__/. Try out the API using Swagger 25 | 5. Alternatively, try hitting the API in a new terminal window using a command like: `curl -X POST "http://127.0.0.1:8000/predict?cyl=4&disp=120&hp=120"` 26 | 1. Try changing the values given to `cyl`, `disp` and `hp`. -------------------------------------------------------------------------------- /04-docker-and-r/04-deploy-models-in-docker/model/build-model.R: -------------------------------------------------------------------------------- 1 | lm_model <- lm(mpg ~ cyl + disp + hp, data = mtcars) 2 | 3 | lm_model 4 | 5 | saveRDS(lm_model, "lm_model.rds") 6 | -------------------------------------------------------------------------------- /04-docker-and-r/04-deploy-models-in-docker/model/lm_model.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsangole/user2022-r-for-docker/1d0551b60970b6836182f3ef79a26ee58a86cb8c/04-docker-and-r/04-deploy-models-in-docker/model/lm_model.rds -------------------------------------------------------------------------------- /04-docker-and-r/04-deploy-models-in-docker/model/plumb-model.R: -------------------------------------------------------------------------------- 1 | message("Running plumb-model.R") 2 | 3 | library(plumber) 4 | 5 | lm_model <- readRDS("lm_model.rds") 6 | 7 | pr("predict.R") |> 8 | pr_run(port=8000, host="0.0.0.0") -------------------------------------------------------------------------------- /04-docker-and-r/04-deploy-models-in-docker/model/predict.R: -------------------------------------------------------------------------------- 1 | #* @param cyl cylinders 2 | #* @param disp displacement 3 | #* @param hp horsepower 4 | #* @post /predict 5 | function(req, cyl = 4, disp = 100, hp = 120) { 6 | 7 | message(sprintf("Running prediction function with {cyl: %s, disp: %s, hp: %s}", 8 | cyl, disp, hp)) 9 | 10 | newdata <- data.frame( 11 | cyl = as.numeric(cyl), 12 | disp = as.numeric(disp), 13 | hp = as.numeric(hp) 14 | ) 15 | 16 | predict(lm_model, newdata) 17 | } -------------------------------------------------------------------------------- /04-docker-and-r/05-deploy-shiny-in-docker/01-docker-build.sh: -------------------------------------------------------------------------------- 1 | docker build --progress=plain . -t docker_for_r/shiny_deployment:v1.0 -------------------------------------------------------------------------------- /04-docker-and-r/05-deploy-shiny-in-docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/shiny:4.2.0 2 | 3 | LABEL purpose="Example of shiny deployment in Docker" 4 | 5 | WORKDIR /home/app 6 | COPY my_app . 7 | 8 | EXPOSE 3838 9 | 10 | CMD ["R", "-e", "options(shiny.port = 3838, shiny.host = '0.0.0.0'); shiny::runApp('/home/app')"] -------------------------------------------------------------------------------- /04-docker-and-r/05-deploy-shiny-in-docker/README.md: -------------------------------------------------------------------------------- 1 | # Deploy Shiny App 2 | 3 | This is an example of how we can deploy a shiny app in Docker. In this example, the needed packages as well as the Shiny app codebase is embeded in the image. No external volumes are mounted. 4 | 5 | The `my_app/` folder holds a simple shiny app. This can be extended to a Shiny app of any complexity. 6 | 7 | # Instructions 8 | 9 | 1. Open and read the `Dockerfile`. 10 | 1. Note that we're now using a different base image here - `rstudio/shiny`. This is an image already configured with the `{shiny}` package. While we could start with our previous `rocker/r-ver` or `rocker/rstudio` images, the build for `{shiny}` takes quite a while. 11 | 2. We create a directory `/home/app` in the image, and copy over the needed files from `my_app/` into it 12 | 3. Finally, run `shiny::runApp` to serve the app over port 3838 13 | 2. Execute `01-docker-build.sh` by running `./01-docker-build.sh` in your terminal. This will build a new image called `docker_for_r/shiny_deployment:v1.0`. 14 | 3. Once built, in your terminal: 15 | 1. Run `docker run -p 3838:3838 docker_for_r/shiny_deployment:v1.0`. 16 | 2. _OR_ run `docker-compose up`. 17 | 3. You should see outputs like: 18 | ``` 19 | R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics" 20 | ... 21 | ... 22 | 23 | > options(shiny.port = 3838, shiny.host = '0.0.0.0'); shiny::runApp('/home/app') 24 | Loading required package: shiny 25 | 26 | Listening on http://0.0.0.0:3838 27 | ``` 28 | 4. Open your browser to http://0.0.0.0:3838 to interact with the app. 29 | 5. `control + C` to stop the container. -------------------------------------------------------------------------------- /04-docker-and-r/05-deploy-shiny-in-docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.9" 2 | services: 3 | my_shiny_app: 4 | image: docker_for_r/shiny_deployment:v1.0 5 | ports: 6 | - "3838:3838" -------------------------------------------------------------------------------- /04-docker-and-r/05-deploy-shiny-in-docker/my_app/app.R: -------------------------------------------------------------------------------- 1 | # 2 | # This is a Shiny web application. You can run the application by clicking 3 | # the 'Run App' button above. 4 | # 5 | # Find out more about building applications with Shiny here: 6 | # 7 | # http://shiny.rstudio.com/ 8 | # 9 | 10 | library(shiny) 11 | 12 | # Define UI for application that draws a histogram 13 | ui <- fluidPage( 14 | 15 | # Application title 16 | titlePanel("Old Faithful Geyser Data"), 17 | 18 | # Sidebar with a slider input for number of bins 19 | sidebarLayout( 20 | sidebarPanel( 21 | sliderInput("bins", 22 | "Number of bins:", 23 | min = 1, 24 | max = 50, 25 | value = 30) 26 | ), 27 | 28 | # Show a plot of the generated distribution 29 | mainPanel( 30 | plotOutput("distPlot") 31 | ) 32 | ) 33 | ) 34 | 35 | # Define server logic required to draw a histogram 36 | server <- function(input, output) { 37 | 38 | output$distPlot <- renderPlot({ 39 | # generate bins based on input$bins from ui.R 40 | x <- faithful[, 2] 41 | bins <- seq(min(x), max(x), length.out = input$bins + 1) 42 | 43 | # draw the histogram with the specified number of bins 44 | hist(x, breaks = bins, col = 'darkgray', border = 'white') 45 | }) 46 | } 47 | 48 | # Run the application 49 | shinyApp(ui = ui, server = server) 50 | -------------------------------------------------------------------------------- /04-docker-and-r/README.md: -------------------------------------------------------------------------------- 1 | # Docker and R 2 | 3 | This section introduces you to how to use R and Docker together. We start with a simple examples and move on to more advanced use cases. 4 | 5 | We'll start of with an introduction to some useful base images, then look at installing R packages, look at how to develop in an IDE, and then move on to deploying scripts, models and shiny in Docker. 6 | 7 | R + Docker can be thought of roughly in a few paradigms: 8 | 9 | 1. Docker provides an R-based development environment 10 | 1. R Packages and environment setup resides _in_ Docker 11 | 2. Code & data resides _outside_ Docker 12 | 2. Docker runs data ETL pipelines 13 | 1. Code, R Packages and environment setup resides _in_ Docker 14 | 2. Data & side effects reside _outside_ Docker 15 | 3. Docker runs predictive models 16 | 1. Code, R Packages and environment setup resides _in_ Docker 17 | 2. Data & side effects reside _outside_ Docker 18 | 4. Docker runs shiny dashboards 19 | 1. Code, Data, R Packages and environment setup resides _in_ Docker 20 | 21 | -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: 2 | // https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/docker-existing-docker-compose 3 | // If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml. 4 | { 5 | // Use any name you like 6 | "name": "Project Container", 7 | // Update the 'dockerComposeFile' list if you have more compose files or use different names. 8 | // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. 9 | "dockerComposeFile": [ 10 | "../docker-compose.yml", 11 | "docker-compose.yml" 12 | ], 13 | // The 'service' property is the name of the service for the container that VS Code should 14 | // use. Update this value and .devcontainer/docker-compose.yml to the real service name. 15 | "service": "rstudio", 16 | // The optional 'workspaceFolder' property is the path VS Code should open by default when 17 | // connected. This is typically a file mount in .devcontainer/docker-compose.yml 18 | "workspaceFolder": "/home/", 19 | // Set *default* container specific settings.json values on container create. 20 | "settings": { 21 | "terminal.integrated.automationShell.linux": "/bin/bash" 22 | }, 23 | // Add the IDs of extensions you want installed when the container is created. 24 | "extensions": [ 25 | "ms-azuretools.vscode-docker", // Makes it easy to create, manage, and debug containerized applications 26 | "mhutchie.git-graph", // View a Git Graph of your repository, and perform Git actions from the graph 27 | "eamodio.gitlens", // Visualize code authorship at a glance via Git blame annotations and CodeLens 28 | "yzhang.markdown-all-in-one", // All you need to write Markdown (keyboard shortcuts, table of contents, auto preview and more) 29 | "tomoki1207.pdf", // Display pdf file in VSCode 30 | "hediet.vscode-drawio", // This unofficial extension integrates Draw.io into VSCode 31 | "janisdd.vscode-edit-csv", // Edit CSV files with a table ui 32 | "REditorSupport.r", 33 | "REditorSupport.r-lsp", // R Extension for Visual Studio Code 34 | "RDebugger.r-debugger", // R Debugger for VS Code 35 | "christian-kohler.path-intellisense", // Visual Studio Code plugin that autocompletes filenames 36 | "ionutvmi.path-autocomplete", 37 | "wwm.better-align", // Align code without selecting them first. 38 | "ms-ossdata.vscode-postgresql", // Develop Postgres everywhere 39 | "mtxr.sqltools" // Database management done right. Connection explorer, query runner, intellisense, bookmarks, query history. 40 | // "vscodevim.vim" // Vim emulation 41 | // "ecmel.vscode-html-css", //CSS Intellisense for HTML 42 | ], 43 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 44 | // "forwardPorts": [], 45 | // Uncomment the next line if you want start specific services in your Docker Compose config. 46 | // "runServices": [], 47 | // Uncomment the next line if you want to keep your containers running after VS Code shuts down. 48 | // "shutdownAction": "none", 49 | // Uncomment the next line to run commands after the container is created - for example installing curl. 50 | "postCreateCommand": "radian" 51 | // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. 52 | // "remoteUser": "vscode" 53 | } -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/.devcontainer/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | services: 3 | # Update this to the name of the service you want to work with in your docker-compose.yml file 4 | rstudio: 5 | # If you want add a non-root user to your Dockerfile, you can use the "remoteUser" 6 | # property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks, 7 | # debugging) to execute as the user. Uncomment the next line if you want the entire 8 | # container to run as this user instead. Note that, on Linux, you may need to 9 | # ensure the UID and GID of the container user you create matches your local user. 10 | # See https://aka.ms/vscode-remote/containers/non-root for details. 11 | # 12 | # user: vscode 13 | 14 | # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer 15 | # folder. Note that the path of the Dockerfile and context is relative to the *primary* 16 | # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile" 17 | # array). The sample below assumes your primary file is in the root of your project. 18 | # 19 | # build: 20 | # context: . 21 | # dockerfile: .devcontainer/Dockerfile 22 | 23 | volumes: 24 | # Update this to wherever you want VS Code to mount the folder of your project 25 | - .:/workspace:cached 26 | # Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details. 27 | # - /var/run/docker.sock:/var/run/docker.sock 28 | 29 | # Overrides default command so things don't shut down after the process ends. 30 | command: /bin/sh -c "while sleep 1000; do :; done" 31 | -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/.lintr: -------------------------------------------------------------------------------- 1 | linters: with_defaults( 2 | line_length_linter(120), 3 | object_usage_linter = NULL, 4 | commented_code_linter = NULL 5 | ) -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "R-Debugger", 9 | "name": "Launch R-Workspace", 10 | "request": "launch", 11 | "debugMode": "workspace", 12 | "workingDirectory": "${workspaceFolder}" 13 | }, 14 | { 15 | "type": "R-Debugger", 16 | "name": "Debug R-File", 17 | "request": "launch", 18 | "debugMode": "file", 19 | "workingDirectory": "${workspaceFolder}", 20 | "file": "${file}" 21 | }, 22 | { 23 | "type": "R-Debugger", 24 | "name": "Debug R-Function", 25 | "request": "launch", 26 | "debugMode": "function", 27 | "workingDirectory": "${workspaceFolder}", 28 | "file": "${file}", 29 | "mainFunction": "main", 30 | "allowGlobalDebugging": false 31 | }, 32 | { 33 | "type": "R-Debugger", 34 | "name": "Debug R-Package", 35 | "request": "launch", 36 | "debugMode": "workspace", 37 | "workingDirectory": "${workspaceFolder}", 38 | "includePackageScopes": true, 39 | "loadPackages": [ 40 | "." 41 | ] 42 | }, 43 | { 44 | "type": "R-Debugger", 45 | "request": "attach", 46 | "name": "Attach to R process", 47 | "splitOverwrittenOutput": true 48 | } 49 | ] 50 | } -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // R setup 3 | "r.alwaysUseActiveTerminal": false, // depending on your workflow 4 | "r.rterm.linux": "/usr/local/bin/radian", 5 | "r.rterm.mac": " /usr/local/bin/radian", 6 | "r.plot.useHttpgd": true, 7 | "[r]": { 8 | "editor.defaultFormatter": "REditorSupport.r", 9 | "editor.formatOnSave": true, 10 | "editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\|;:'\",<>/?" // Treat names.like.this as one word for selection. 11 | }, 12 | "[rmd]": { 13 | "editor.defaultFormatter": "REditorSupport.r", 14 | "editor.formatOnSave": true 15 | }, 16 | "files.associations": { // required 17 | "*.rmd": "markdown", 18 | "*.Rmd": "rmd" 19 | }, 20 | "r.bracketedPaste": true, 21 | "r.lsp.enabled": true, 22 | "r.lsp.diagnostics": false, 23 | "r.session.levelOfObjectDetail": "Normal", 24 | "r.session.viewers.viewColumn": { 25 | "plot": "Three", 26 | "browser": "Three", 27 | "viewer": "Two", 28 | "pageViewer": "Active", 29 | "view": "Three", 30 | "helpPanel": "Three" 31 | }, 32 | // Python 33 | // "python.defaultInterpreterPath": "/usr/local/bin/python3", // Check your python path, if exists in your Docker image 34 | // "jupyter.interactiveWindowMode": "perFile", 35 | // VSCode setup 36 | "path-autocomplete.pathMappings": { 37 | "/": "/", 38 | "./": "${folder}" 39 | }, 40 | "editor.suggestSelection": "recentlyUsedByPrefix", 41 | "editor.formatOnSave": true, 42 | "editor.formatOnPaste": true, 43 | "editor.formatOnType": true, 44 | "diffEditor.ignoreTrimWhitespace": true, 45 | "search.showLineNumbers": true, 46 | // Additional Optional Settings 47 | // "workbench.startupEditor":"none", 48 | // "workbench.iconTheme": "VSCode Great Icons", // optional 49 | // "workbench.colorTheme": "Visual Studio Light", // optional 50 | // "diffEditor.ignoreTrimWhitespace": false, // optional 51 | // "files.autoSave": "off", // optional 52 | // "explorer.confirmDragAndDrop": false, 53 | // "explorer.confirmDelete": false, // optional 54 | // "vim.highlightedyank.enable": true, 55 | // "vim.smartRelativeLine": true, 56 | // "vsicons.dontShowNewVersionMessage": true, 57 | // "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", 58 | } -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/01-docker-build.sh: -------------------------------------------------------------------------------- 1 | docker build . -t hatmatrix/r_vscode:v1.0 -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/r-ver:4.2.0 2 | 3 | LABEL purpose="Example of setup for VS Code" 4 | 5 | RUN apt-get update && apt-get install -y --no-install-recommends \ 6 | python3-pip \ 7 | libxml2-dev \ 8 | libfontconfig1-dev \ 9 | && pip install -U radian 10 | 11 | ENV RENV_VERSION 0.15.5 12 | RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))" 13 | RUN R -e "remotes::install_github('rstudio/renv@${RENV_VERSION}')" 14 | 15 | WORKDIR /renv 16 | COPY renv.lock renv.lock 17 | 18 | RUN R -e "renv::restore()" 19 | -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/README.md: -------------------------------------------------------------------------------- 1 | Detailed instructions are found in [REditorSupport/vscode-R](https://github.com/REditorSupport/vscode-R/wiki/Installation:-Linux). 2 | 3 | ### tldr: 4 | 5 | **In your Docker image** 6 | 7 | - Install [`radian`](https://github.com/randy3k/radian) using this line in your Dockerfile: 8 | ``` 9 | RUN apt-get update && apt-get install -y --no-install-recommends \ 10 | python3-pip \ 11 | && pip install -U radian 12 | ``` 13 | 14 | - Make sure `{languageserver}` is installed in your R setup 15 | - To ensure plotting works, make sure `{httpgd}` is installed in your R setup 16 | - For debugging to work with the `VSCode-R-Debugger` extension, ensure `vscDebugger` is installed using `remotes::install_github("ManuelHentschel/vscDebugger")` 17 | - Edit `docker-compose.yml`. Add environment variables as needed. Edit `$PROJECT_DATA_DIR` to your project's data directory if needed. 18 | - _Optionally_ edit `.devcontainer/devcontainer.json`. Manipulate the `"extensions"` as you see fit. 19 | - _Optionally_ edit `.vscode/settings.json`. All the recommended settings have been set. Manipulate as needed. -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.9" 2 | services: 3 | rstudio: 4 | image: hatmatrix/r_vscode:v1.0 5 | environment: 6 | DISABLE_AUTH: "true" 7 | YOUR_ENV_VARIABLES: "go_here" 8 | volumes: 9 | - type: "bind" 10 | source: "/Users/rahul/github/github.com/user2022-r-for-docker/05-dev-environments/02-vscode-ide" 11 | target: "/home/projects/" -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/renv.lock: -------------------------------------------------------------------------------- 1 | { 2 | "R": { 3 | "Version": "4.2.0", 4 | "Repositories": [ 5 | { 6 | "Name": "CRAN", 7 | "URL": "https://cloud.r-project.org" 8 | } 9 | ] 10 | }, 11 | "Packages": { 12 | "languageserver": { 13 | "Package": "languageserver", 14 | "Version": "0.3.13", 15 | "Source": "Repository" 16 | }, 17 | "httpgd": { 18 | "Package": "httpgd", 19 | "Version": "1.3.0", 20 | "Source": "Repository" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /05-dev-environments/01-vscode-ide/test.R: -------------------------------------------------------------------------------- 1 | library(rpart) 2 | 3 | rpart(mpg~., mtcars) 4 | -------------------------------------------------------------------------------- /05-dev-environments/package.template/.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /05-dev-environments/package.template/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: package.template 2 | Type: Package 3 | Title: Example for R package with Docker workflow for the useR! 2022 Docker for R users workshop 4 | Version: 0.1.0.9000 5 | Authors@R: c(person(given = "Rami", 6 | family ="Krispin", 7 | email = "rami.krispin@gmail.com", 8 | role = c("aut", "cre")), 9 | person(given = "Rahul", 10 | family = "Sangole", 11 | role = c("aut", "cre"), 12 | email = "rahul.sangole@gmail.com")) 13 | Maintainer: Rami Krispin 14 | Description: The package provides an example to integration of Docker with R package development. 15 | That includes setting RStudio server with Docker and integration with Github Actions. 16 | License: MIT + file LICENSE 17 | Encoding: UTF-8 18 | LazyData: true 19 | Depends: 20 | R (>= 3.0.2) 21 | Suggests: 22 | dplyr, 23 | knitr, 24 | ggplot, 25 | rmarkdown, 26 | testthat (>= 2.1.0) 27 | RoxygenNote: 7.1.2 28 | -------------------------------------------------------------------------------- /05-dev-environments/package.template/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(line_plot) 4 | -------------------------------------------------------------------------------- /05-dev-environments/package.template/R/functions.R: -------------------------------------------------------------------------------- 1 | #' Function for plotting Two Dimension 2 | #' @description The function create a two dimension line plot with ggplot2 3 | #' @details The function get two inputs, x and y, and returns a line plot 4 | #' @param x A numeric, represents the x-axis 5 | #' @param y A numeric, represents the y-axis 6 | #' @param point A bolean, if set to TRUE (default), add geom_point to the plot 7 | #' @return A ggplot2 line chart 8 | #' @export 9 | #' @examples 10 | #' 11 | #' line_plot(x = c(1:100), y = rnorm(n = 100, mean = 10, sd = 2)) 12 | #' # Without geom_point 13 | #' line_plot(x = c(1:100), y = rnorm(n = 100, mean = 10, sd = 2), point = FALSE) 14 | #' 15 | 16 | line_plot<- function(x, y, point = TRUE){ 17 | df <- data.frame(x = x, y = y) 18 | 19 | if(point){ 20 | ggplot2::ggplot(data=df, ggplot2::aes(x=x, y=y)) + 21 | ggplot2::geom_line()+ 22 | ggplot2::geom_point() 23 | } else { 24 | ggplot2::ggplot(data=df, ggplot2::aes(x=x, y=y)) + 25 | ggplot2::geom_line() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /05-dev-environments/package.template/docker/dev/build_docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "\033[0;92mStart to build the docker" 4 | echo "\033[0;92mTag: 0.1.0.9000" 5 | 6 | docker build . -t rkrispin/package_template_dev:0.1.0.9000 7 | 8 | # Pushing the docker to Docker Hub 9 | # Use "docker login" to login to your account 10 | if [[ $? = 0 ]] ; then 11 | echo "\033[0;92mPushing docker..." 12 | docker push rkrispin/package_template_dev:0.1.0.9000 13 | else 14 | echo "\033[0;91mmDocker build failed" 15 | fi -------------------------------------------------------------------------------- /05-dev-environments/package.template/docker/dev/dockerfile: -------------------------------------------------------------------------------- 1 | # Using ubuntu:18.04 base image 2 | # Installing base R version 4.0.0 with minimum requirements 3 | # Code: https://github.com/RamiKrispin/dockerfiles/blob/main/r-base-4/Dockerfile 4 | # Docker Hub: https://hub.docker.com/r/rkrispin/baser4/tags 5 | FROM rkrispin/baser:v4.2.0 6 | 7 | LABEL maintainers="Rami Krispin , Rahul Sangole " 8 | 9 | RUN mkdir pkgs 10 | COPY *.R pkgs/ 11 | 12 | RUN Rscript pkgs/install_packages.R -------------------------------------------------------------------------------- /05-dev-environments/package.template/docker/dev/install_packages.R: -------------------------------------------------------------------------------- 1 | # Installing R packages inside docker 2 | # Setting ---- 3 | cran_mirror <- "https://cran.rstudio.com/" 4 | quiet <- FALSE # Set TRUE for clean output, when testing or getting errors use FALSE 5 | 6 | # Set packages and their version (optional) 7 | pkg_list <- data.frame(package = c("knitr", "ggplot", "rmarkdown", "testthat"), 8 | version = c(NA, NA, NA, NA), 9 | stringsAsFactors = FALSE) 10 | 11 | pkg_list$status <- NA 12 | 13 | # Installing ---- 14 | # Installing remotes in case package required specific version 15 | if(!all(is.na(pkg_list$version))){ 16 | install.packages("remotes", repos = cran_mirror) 17 | } 18 | 19 | for(i in 1:nrow(pkg_list)){ 20 | cat("\033[0;92m", paste("Installing", pkg_list$package[i]), "\033[0m\n", sep = "") 21 | if(is.na(pkg_list$version[i])){ 22 | # No package version 23 | # Installing the most recent version from CRAN 24 | install.packages(pkgs = pkg_list$package, 25 | repos = cran_mirror, 26 | quiet = quiet) 27 | } else { 28 | # Installing specific version 29 | remotes::install_version(package = pkg_list$package[i], 30 | version = pkg_list$version[i], 31 | dependencies = c("Depends", "Imports"), 32 | upgrade = FALSE, 33 | #verbose = FALSE, 34 | quiet = quiet, 35 | repos = cran_mirror) 36 | 37 | 38 | } 39 | 40 | if(i %in% rownames(installed.packages())){ 41 | pkg_list$status[i] <- TRUE 42 | } else { 43 | pkg_list$status[i] <- FALSE 44 | } 45 | } 46 | # Return report 47 | for(i in 1:nrow(pkg_list)){ 48 | if(pkg_list$status[i]){ 49 | cat("\033[0;92m", paste(pkg_list$package[i]),"...installed successfully", "\033[0m\n", sep = "") 50 | } else { 51 | cat("\033[0;91m", paste(pkg_list$package[i]),"...failed", "\033[0m\n", sep = "") 52 | } 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /05-dev-environments/package.template/man/line_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/functions.R 3 | \name{line_plot} 4 | \alias{line_plot} 5 | \title{Function for plotting Two Dimension} 6 | \usage{ 7 | line_plot(x, y, point = TRUE) 8 | } 9 | \arguments{ 10 | \item{x}{A numeric, represents the x-axis} 11 | 12 | \item{y}{A numeric, represents the y-axis} 13 | 14 | \item{point}{A bolean, if set to TRUE (default), add geom_point to the plot} 15 | } 16 | \value{ 17 | A ggplot2 line chart 18 | } 19 | \description{ 20 | The function create a two dimension line plot with ggplot2 21 | } 22 | \details{ 23 | The function get two inputs, x and y, and returns a line plot 24 | } 25 | \examples{ 26 | 27 | line_plot(x = c(1:100), y = rnorm(n = 100, mean = 10, sd = 2)) 28 | # Without geom_point 29 | line_plot(x = c(1:100), y = rnorm(n = 100, mean = 10, sd = 2), point = FALSE) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /05-dev-environments/package.template/package.template.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /06-resources/README.md: -------------------------------------------------------------------------------- 1 | # Useful Links 2 | 3 | - [The Rocker Project](https://www.rocker-project.org) 4 | - [Docker Docs - Getting Started](https://docs.docker.com/get-started/) 5 | - [`{plumber}`](https://www.rplumber.io/index.html) 6 | - [`{renv}`](https://rstudio.github.io/renv/) 7 | - [How to setup and push your images to Docker Hub](https://docs.docker.com/get-started/04_sharing_app/) 8 | 9 | # Useful Tools 10 | 11 | - Top-like interface for container metrics: [ctop](https://github.com/bcicen/ctop) 12 | - A simple terminal UI for both docker and docker-compose: [lazydocker](https://github.com/jesseduffield/lazydocker) 13 | - Collection of easy to read community-maintained help pages for command-line tools: [tldr](https://github.com/tldr-pages/tldr) 14 | 15 | # Useful Tutorials 16 | 17 | - [How to use RStudio & PostgreSQL in Docker](https://rsangole.netlify.app/post/2021/08/07/docker-based-rstudio-postgres/) 18 | - [Free Code Academy - Docker](https://www.youtube.com/c/Freecodecamp/search?query=docker) 19 | -------------------------------------------------------------------------------- /Introduction to Docker for R users.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsangole/user2022-r-for-docker/1d0551b60970b6836182f3ef79a26ee58a86cb8c/Introduction to Docker for R users.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # useR 2022 Docker for R Users Workshop 2 | 3 | ![](https://img.shields.io/badge/status-Complete-green) 4 | 5 | ![](.img/docker_R.001.jpeg) 6 | 7 | - **Presentation Slides** : [Link](https://github.com/rsangole/user2022-r-for-docker/blob/main/Introduction%20to%20Docker%20for%20R%20users.pdf) 8 | - **Video**: To be updated once useR uploads to YouTube 9 | - **Time:** Monday, 20 June 2022, 4:00 - 7:30am CDT / 2:00 - 5:30am PCT 10 | - **More info:** https://user2022.r-project.org/program/tutorials/#docker-for-r-users 11 | 12 | --- 13 | 14 | ### Agenda 15 | 16 | * Kick Off [20 min] : 2:00 - 2:20 17 | * About Us 18 | * Polls 19 | * Code of Conduct 20 | * Engagement Model 21 | * GitHub Repo 22 | * Brief Installation & Testing Review 23 | * Introduction to Docker [30 min] : 2:20 - 2:50 24 | * Motivation For Docker 25 | * Example Usecases 26 | * What is Docker? 27 | * Docker Workflow 28 | * Q & A [10 min] : 2:50 - 3:00 29 | * Break [5 min] : 3:00 - 3:05 30 | * Dockerfile [30 min] : 3:05 - 3:35 31 | * Overview 32 | * Core commands 33 | * Image Layers 34 | * Q & A 35 | * Docker CLI [25 min] : 3:35 - 4:00 36 | * docker commands 37 | * docker-compose commands 38 | * Q & A 39 | * Break [10 min] : 4:00 - 4:10 40 | * Docker + R Basics [45 min] : 4:10 - 4:55 41 | * Introduction to Rocker 42 | * Installing packages 43 | * Develop in Docker 44 | * Deploy Models in Docker 45 | * Deploy Shiny in Docker 46 | * Intermediate Concepts [20 min] : 4:55 - 5:15 47 | * Package Development with GitHub Actions [15 min] 48 | * VS Code, R and Docker [10 min] 49 | * _Stretch Goal - Postgres & R_ 50 | * Summary and Q & A [15 mins] : 5:15 - 5:30 51 | --------------------------------------------------------------------------------