-
Notifications
You must be signed in to change notification settings - Fork 94
/
06-Sharing-all-your-analysis.Rmd
115 lines (82 loc) · 3.14 KB
/
06-Sharing-all-your-analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
title: "06-Share all your analysis"
output:
dcTemplate::dc_lesson_template:
fig_width: 6
fig_height: 6
highlight: pygments
---
Now that we have learned how to work with a dockerfile, we can send all our analysis to a collaborator.
We will share an image that contains all the dependencies that we need to run our analysis, the data and the analysis.
We will build this image via a dockerfile. Let's start with the basic verse rocker image we used before.
This time we want to have a specific R version (3.3.2), which the developers make possible by tagging the images with the version.
See all available tags for the `rocker/verse` image [here](https://hub.docker.com/r/rocker/verse/tags/). The version tag is very
useful when you want your analysis to be reproducible.
```
FROM rocker/verse:3.3.2
```
As part of our analysis, we will use the gapminder data. We will need to install this package into our docker image.
Let's modify our dockerfile to install this package.
```
RUN R -e "install.packages('gapminder', repos = 'http://cran.us.r-project.org')"
```
Now we just need to write our analysis and add it to our dockerfile.
For this analysis, we will create a plot of life expectancy vs. gdp per capita.
On a new R script let's write the following analysis.
```{r}
library(ggplot2)
library(gapminder)
life_expentancy_plot <- ggplot(data = gapminder) +
geom_point(aes(x = lifeExp, y = gdpPercap, colour = continent))
```
We will save this r script as analysis.R and add it to our dockerfile.
```
ADD analysis.R /home/rstudio/
```
Now we can build the image and check that we have everything we want to share with our collaborator.
```
docker build -t my-analysis .
```
Our analysis will appear on the list of images.
```
docker images
```
Launch your new image and check you have everything you want to include:
```
docker run -dp 8787:8787 my-analysis
```
Great! our analysis script is there and gapminder is installed.
Now we can push our analysis to dockerhub.
On dockerhub click on *Create Repository*.
Choose a name (e.g. gapminder_my_analysis) and a description for your repository and click *Create*.
Log into the Docker Hub from the command line
```{}
docker login --username=yourhubusername
```
just with your own user name that you used for the account.
Enter your password when prompted.
Check the image ID using
```{}
docker images
```
and what you will see will be similar to
```{}
REPOSITORY TAG IMAGE ID CREATED SIZE
my-analysis latest dc63d4790eaa 2 minutes ago 3.164 GB
```
and tag your image
```{}
docker tag dc63d4790eaa yourhubusername/gapminder_my_analysis:firsttry
```
Push your image to the repository you created
```{}
docker push yourhubusername/gapminder_my_analysis
```
Your image is now available for everyone to use.
Now your collaborator can download your image.
Your collaborator should write on their command line:
```
docker pull yourhubusername/gapminder_my_analysis:firsttry
```
They now have the image of your analysis.
Click to go back to the [main page](http://jsta.github.io/r-docker-tutorial/).