Skip to content

Commit 9bb2184

Browse files
committed
update
1 parent 94f035a commit 9bb2184

File tree

12 files changed

+443
-0
lines changed

12 files changed

+443
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.directory
2+
mountpoints/apps/*
3+
!mountpoints/apps/index.html
4+
!mountpoints/apps/example-app

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM rocker/r-ver:3.6.3
2+
3+
RUN apt-get update && apt-get install -y \
4+
sudo \
5+
gdebi-core \
6+
pandoc \
7+
pandoc-citeproc \
8+
libcurl4-gnutls-dev \
9+
libcairo2-dev \
10+
libxt-dev \
11+
xtail \
12+
wget
13+
14+
15+
# Download and install shiny server
16+
RUN wget --no-verbose https://download3.rstudio.org/ubuntu-14.04/x86_64/VERSION -O "version.txt" && \
17+
VERSION=$(cat version.txt) && \
18+
wget --no-verbose "https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
19+
gdebi -n ss-latest.deb && \
20+
rm -f version.txt ss-latest.deb && \
21+
. /etc/environment && \
22+
R -e "install.packages(c('shiny', 'rmarkdown'), repos='$MRAN')" && \
23+
cp -R /usr/local/lib/R/site-library/shiny/examples/* /srv/shiny-server/ && \
24+
chown shiny:shiny /var/lib/shiny-server
25+
26+
EXPOSE 3838
27+
28+
COPY shiny-server.sh /usr/bin/shiny-server.sh
29+
30+
CMD ["/usr/bin/shiny-server.sh"]

README.md

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
Docker for Shiny Server
2+
=======================
3+
4+
![](https://img.shields.io/docker/build/rocker/shiny.svg) ![](https://img.shields.io/docker/build/rocker/shiny-verse.svg)
5+
6+
This is a Dockerfile for Shiny Server on Debian stable. Dockerfiles building on specific versions of R are now available as tags. These images are based on the corresponding [r-ver](https://hub.docker.com/r/rocker/r-ver) image. You can request a specific R version using the appropriate tag, e.g. `rocker/shiny:3.3.2`.
7+
8+
***For documentation for R >= 4.0.0, for images `r-ver`, `rstudio`, `tidyverse`, `verse`, `geospatial`, `shiny`, and `binder`, please see the [`rocker-versioned2` repository`](https://github.com/rocker-org/rocker-versioned2).***
9+
10+
11+
## Usage:
12+
13+
14+
To run a temporary container with Shiny Server:
15+
16+
```sh
17+
docker run --rm -p 3838:3838 rocker/shiny
18+
```
19+
20+
To get specific version of R with your shiny image (e.g. 3.4.4):
21+
22+
23+
```sh
24+
docker run --rm -p 3838:3838 rocker/shiny:3.4.4
25+
```
26+
27+
### Developer Notes
28+
29+
- **avoid `apt-get install r-cran-*`** on this image stack. The requested R version and all R packages are installed from source in the version-stable stack. Installing R packages from `apt` (e.g. the `r-cran-*` packages) will install the version of R and versions of the packages that were built for the stable debian release (e.g. `debian:stretch`), giving you a second version of R and different packages. Please install R packages from source using the `install.packages()` R function (or the `install2.r` script), and use `apt` only to install necessary system libraries (e.g. `libxml2`). If you would prefer to install only the latest verions of packages from pre-built binaries using `apt-get`, consider using the `r-base` stack instead. See [rocker-versioned README](https://github.com/rocker-org/rocker-versioned) for details on extending these images.
30+
31+
### shiny-verse
32+
33+
You can use `rocker/shiny-verse` image stack instead if you'd like `tidyverse` packages pre-installed on your instance of shiny.
34+
35+
### Connecting app and log directories to host
36+
37+
To expose a directory on the host to the container, use `-v <host_dir>:<container_dir>`. The following command will use one `/srv/shinyapps` as the Shiny app directory and `/srv/shinylog` as the directory for Shiny app logs. Note that if the directories on the host don't already exist, they will be created automatically.:
38+
39+
```sh
40+
docker run --rm -p 3838:3838 \
41+
-v /srv/shinyapps/:/srv/shiny-server/ \
42+
-v /srv/shinylog/:/var/log/shiny-server/ \
43+
rocker/shiny
44+
```
45+
46+
If you have an app in `/srv/shinyapps/appdir`, you can run the app by visiting http://localhost:3838/appdir/. (If using boot2docker, visit http://192.168.59.103:3838/appdir/)
47+
48+
In a real deployment scenario, you will probably want to run the container in detached mode (`-d`) and listening on the host's port 80 (`-p 80:3838`):
49+
50+
```sh
51+
docker run -d -p 80:3838 \
52+
-v /srv/shinyapps/:/srv/shiny-server/ \
53+
-v /srv/shinylog/:/var/log/shiny-server/ \
54+
rocker/shiny
55+
```
56+
57+
### Warnings
58+
59+
In the logs, you may see a note that shiny is running as root. To run as a regular user, simply set the user in your Docker run command, e.g.
60+
61+
```sh
62+
docker run --user shiny -p 3838:3838 --rm rocker/shiny
63+
```
64+
65+
66+
### Logs
67+
68+
The Shiny Server log and all application logs are written to `stdout` and can be viewed using `docker logs`.
69+
70+
The logs for individual apps are still kept in the `/var/log/shiny-server` directory, as described in the [Shiny Server Administrator's Guide]( http://docs.rstudio.com/shiny-server/#application-error-logs). If you want to avoid printing the logs to STDOUT, set up the environment variable `APPLICATION_LOGS_TO_STDOUT` to `false` (`-e APPLICATION_LOGS_TO_STDOUT=false`).
71+
72+
73+
### With docker-compose
74+
75+
This repository includes an example `docker-compose` file, to facilitate using this container within docker networks.
76+
77+
#### To run a container with Shiny Server:
78+
79+
```sh
80+
docker-compose up
81+
```
82+
83+
Then visit `http://localhost` (i.e., `http://localhost:80`) in a web browser. If you have an app in `/srv/shinyapps/appdir`, you can run the app by visiting http://localhost/appdir/.
84+
85+
#### To add a Shiny app:
86+
87+
1. Uncomment the last line of `docker-compose.yml`.
88+
1. Place the app in `mountpoints/apps/the-name-of-the-app`, replacing `the-name-of-the-app` with your app's name.
89+
90+
If you have an app in `mountpoints/apps/appdir`, you can run the app by visiting http://localhost/appdir/. (If using boot2docker, visit http://192.168.59.103:3838/appdir/)
91+
92+
#### Logs
93+
94+
The example `docker-compose` file will create a persistent volume for server logs, so that log data will persist across instances where the container is running. To access these logs, while the container is running, run `docker exec -it shiny bash` and then `ls /var/log/shiny-server` to see the available logs. To copy these logs to the host system for inspection, while the container is running, you can use, for example, `docker cp shiny:/var/log/shiny-server ./logs_for_inspection`.
95+
96+
#### Detached mode
97+
98+
In a real deployment scenario, you will probably want to run the container in detached mode (`-d`):
99+
100+
```sh
101+
docker-compose up -d
102+
```
103+
104+
### Custom configuration
105+
106+
To add a custom configuration file, assuming the custom file is called `shiny-customized.config`, uncomment the line
107+
108+
```
109+
COPY shiny-customized.config /etc/shiny-server/shiny-server.conf
110+
```
111+
112+
in the `Dockerfile`, and then run `docker-compose build shiny` to rebuild the container. Inline comments above that line in the `Dockerfile` provide additional documentation.
113+
114+
## Trademarks
115+
116+
Shiny and Shiny Server are registered trademarks of RStudio, Inc. The use of the trademarked terms Shiny and Shiny Server and the distribution of the Shiny Server through the images hosted on hub.docker.com has been granted by explicit permission of RStudio. Please review RStudio's trademark use policy and address inquiries about further distribution or other questions to [email protected].

docker-compose.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: "3.0"
2+
3+
services:
4+
shiny:
5+
container_name: shiny
6+
# To build the image locally, comment out "image" below, and uncomment
7+
# "build" and the lines indented under it.
8+
# image: rocker/shiny
9+
build:
10+
context: .
11+
dockerfile: Dockerfile
12+
restart: always
13+
# Setting this to something other than 'root' will cause shiny apps not to
14+
# run on the localhost:80 "Welcome to Shiny" diagnostics page mentioned
15+
# below.
16+
user: 'root'
17+
# Uncomment the lines below to disable application logs STDOUT output
18+
# environment:
19+
# - APPLICATION_LOGS_TO_STDOUT=false
20+
ports:
21+
- '80:3838'
22+
volumes:
23+
- 'shiny_logs:/var/log/shiny-server'
24+
# Comment the line below out for initial testing. With it commented out,
25+
# going to localhost:80 in one's web browser will show a "Welcome to
26+
# Shiny Server!" diagnostics page.
27+
# - './mountpoints/apps:/srv/shiny-server'
28+
29+
volumes:
30+
shiny_logs:

hooks/post_push

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Working dir and contents I see are:"
5+
echo `pwd`
6+
echo `ls`
7+
8+
## Not all bash commands are available. notably grep -o -e options fail!!
9+
VERSION=`cat Dockerfile | head -n1 | sed 's/.*\([0-9].[0-9].[0-9]\)/\1/'`
10+
echo "Version being built is:"
11+
echo $VERSION
12+
13+
echo "tagging $IMAGE_NAME as $DOCKER_REPO:$VERSION..."
14+
docker tag $IMAGE_NAME $DOCKER_REPO:$VERSION
15+
16+
echo "pushing $DOCKER_REPO:$VERSION to hub..."
17+
docker push $DOCKER_REPO:$VERSION
18+
19+
20+
# docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_BRANCH
21+
# docker push $DOCKER_REPO:$SOURCE_BRANCH
22+
23+

mountpoints/apps/example-app/server.R

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This is the server logic of a Shiny web application. You can run the
3+
# application by clicking 'Run App' 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 server logic required to draw a histogram
13+
shinyServer(function(input, output) {
14+
15+
output$distPlot <- renderPlot({
16+
17+
# generate bins based on input$bins from ui.R
18+
x <- faithful[, 2]
19+
bins <- seq(min(x), max(x), length.out = input$bins + 1)
20+
21+
# draw the histogram with the specified number of bins
22+
hist(x, breaks = bins, col = 'darkgray', border = 'white')
23+
24+
})
25+
26+
})

mountpoints/apps/example-app/ui.R

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# This is the user-interface definition of a Shiny web application. You can
3+
# run the application by clicking 'Run App' 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+
shinyUI(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+
))

mountpoints/apps/index.html

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!DOCTYPE html>
2+
3+
<!-- This file is modified from https://raw.githubusercontent.com/rstudio/shiny-server/cf0bf138a0ea38ba803ad96a6fef10ccd65f4ff9/samples/welcome.html,
4+
which is at /opt/shiny-server/samples/welcome.html by default in a shiny server. -->
5+
6+
<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
7+
<head>
8+
<title>Welcome to Shiny Server!</title>
9+
<style type="text/css">
10+
body, html {
11+
font-family: Helvetica, Arial, sans-serif;
12+
background-color: #F5F5F5;
13+
color: #114;
14+
margin: 0;
15+
padding: 0;
16+
}
17+
a {
18+
text-decoration: none;
19+
}
20+
a:hover {
21+
text-decoration: underline;
22+
}
23+
#titleBar {
24+
height: 80px;
25+
background-color: #3475b4;
26+
overflow: hidden;
27+
border-bottom: 1px solid #3475b3;
28+
-moz-box-shadow: 0px 0px 10px 3px #BBC;
29+
-webkit-box-shadow: 0px 0px 10px 3px #BBC;
30+
box-shadow: 0px 0px 10px 3px #BBC;
31+
}
32+
#titleBar #container {
33+
margin-top: 14px;
34+
}
35+
#titleBar h1 {
36+
margin: 0 auto .5em auto;
37+
padding: .2em;
38+
color: #EEE;
39+
text-align: center;
40+
}
41+
#intro {
42+
background-color: #DDD;
43+
margin: 1em 1em 0 1em;
44+
padding: .75em;
45+
text-align: center;
46+
border: 1px solid #CCC;
47+
font-size: 18px;
48+
}
49+
#intro p {
50+
margin: .3em 0 .3em 0;
51+
}
52+
#outer-content {
53+
max-width: 910px;
54+
margin-left: auto;
55+
margin-right: auto;
56+
}
57+
#content {
58+
margin: 1em auto 1em auto;
59+
float: left;
60+
}
61+
#main{
62+
margin-right: 350px;
63+
float: left;
64+
line-height: 24px;
65+
}
66+
67+
#shiny{
68+
float: left;
69+
width: 305px;
70+
margin-left: -330px;
71+
padding-left: 20px;
72+
border-left: 1px solid #AAA;
73+
}
74+
#shiny iframe {
75+
margin-top: 30px;
76+
}
77+
.caption{
78+
font-size: 13px;
79+
}
80+
code {
81+
background-color: #E5E5E5;
82+
border: 1px solid #AAA;
83+
-webkit-border-radius: 3px;
84+
-khtml-border-radius: 3px;
85+
-moz-border-radius: 3px;
86+
border-radius: 3px;
87+
padding: 0 .5em 0 .5em;
88+
}
89+
</style>
90+
</head>
91+
<body>
92+
<div id="titleBar">
93+
<div id="container">
94+
<h1>Welcome to Shiny Server!</h1>
95+
</div>
96+
</div>
97+
<div id="outer-content">
98+
<div id="intro">
99+
<p>If you're seeing this page, that means Shiny Server is installed and running. <strong>Further, it is running from your custom mountpoint!</strong> </p>
100+
</div>
101+
</div>
102+
</body>
103+
</html>

shiny-server.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
# Make sure the directory for individual app logs exists
4+
mkdir -p /var/log/shiny-server
5+
chown shiny.shiny /var/log/shiny-server
6+
7+
if [ "$APPLICATION_LOGS_TO_STDOUT" != "false" ];
8+
then
9+
# push the "real" application logs to stdout with xtail in detached mode
10+
exec xtail /var/log/shiny-server/ &
11+
fi
12+
13+
# start shiny server
14+
exec shiny-server 2>&1

0 commit comments

Comments
 (0)