Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Use latest Shiny Server build, and Add docker-compose file #37

Merged
merged 6 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.directory
mountpoints/apps/*
!mountpoints/apps/index.html
!mountpoints/apps/example-app
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ FROM r-base:latest

MAINTAINER Winston Chang "winston@rstudio.com"

# Install dependencies and Download and install shiny server
## Install dependencies and Download and install shiny server

## See https://www.rstudio.com/products/shiny/download-server/ for the
## instructions followed here.

RUN apt-get update && apt-get install -y -t unstable \
sudo \
gdebi-core \
Expand All @@ -11,9 +15,9 @@ RUN apt-get update && apt-get install -y -t unstable \
libcurl4-gnutls-dev \
libcairo2-dev/unstable \
libxt-dev && \
wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
wget --no-verbose https://download3.rstudio.org/ubuntu-14.04/x86_64/VERSION -O "version.txt" && \
VERSION=$(cat version.txt) && \
wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
wget --no-verbose "https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
gdebi -n ss-latest.deb && \
rm -f version.txt ss-latest.deb && \
R -e "install.packages(c('shiny', 'rmarkdown'), repos='https://cran.rstudio.com/')" && \
Expand All @@ -24,4 +28,12 @@ EXPOSE 3838

COPY shiny-server.sh /usr/bin/shiny-server.sh

## Uncomment the line below to include a custom configuration file. You can download the default file at
## https://raw.githubusercontent.com/rstudio/shiny-server/master/config/default.config
## (The line below assumes that you have downloaded the file above to ./shiny-customized.config)
## Documentation on configuration options is available at
## http://docs.rstudio.com/shiny-server/

# COPY shiny-customized.config /etc/shiny-server/shiny-server.conf

CMD ["/usr/bin/shiny-server.sh"]
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ As of January 2017, the Shiny Server log is written to `stdout` and can be viewe

## Usage:

### With docker

To run a temporary container with Shiny Server:

```sh
docker run --rm -p 3838:3838 rocker/shiny
```


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.:
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.:

```sh
docker run --rm -p 3838:3838 \
Expand All @@ -25,8 +26,7 @@ docker run --rm -p 3838:3838 \
rocker/shiny
```

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/)

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/)

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`):

Expand All @@ -37,6 +37,46 @@ docker run -d -p 80:3838 \
rocker/shiny
```

### With docker-compose

This repository includes an example `docker-compose` file, to facilitate using this container within docker networks.

#### To run a container with Shiny Server:

```sh
docker-compose up
```

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/.

#### To add a Shiny app:

1. Uncomment the last line of `docker-compose.yml`.
1. Place the app in `mountpoints/apps/the-name-of-the-app`, replacing `the-name-of-the-app` with your app's name.

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/)

#### Logs

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`.

#### Detached mode

In a real deployment scenario, you will probably want to run the container in detached mode (`-d`):

```sh
docker-compose up -d
```

### Custom configuration

To add a custom configuration file, assuming the custom file is called `shiny-customized.config`, uncomment the line

```
COPY shiny-customized.config /etc/shiny-server/shiny-server.conf
```

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.

## Trademarks

Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3.0"

services:
shiny:
container_name: shiny
# To build the image locally, comment out "image" below, and uncomment
# "build" and the lines indented under it.
# image: rocker/shiny
build:
context: .
dockerfile: Dockerfile
restart: always
# Setting this to something other than 'root' will cause shiny apps not to
# run on the localhost:80 "Welcome to Shiny" diagnostics page mentioned
# below.
user: 'root'
ports:
- '80:3838'
volumes:
- 'shiny_logs:/var/log/shiny-server'
# Comment the line below out for initial testing. With it commented out,
# going to localhost:80 in one's web browser will show a "Welcome to
# Shiny Server!" diagnostics page.
# - './mountpoints/apps:/srv/shiny-server'

volumes:
shiny_logs:
26 changes: 26 additions & 0 deletions mountpoints/apps/example-app/server.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

library(shiny)

# Define server logic required to draw a histogram
shinyServer(function(input, output) {

output$distPlot <- renderPlot({

# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)

# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')

})

})
33 changes: 33 additions & 0 deletions mountpoints/apps/example-app/ui.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# This is the user-interface definition of a Shiny web application. You can
# run the application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
shinyUI(fluidPage(

# Application title
titlePanel("Old Faithful Geyser Data"),

# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),

# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
))
103 changes: 103 additions & 0 deletions mountpoints/apps/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!DOCTYPE html>

<!-- This file is modified from https://raw.githubusercontent.com/rstudio/shiny-server/cf0bf138a0ea38ba803ad96a6fef10ccd65f4ff9/samples/welcome.html,
which is at /opt/shiny-server/samples/welcome.html by default in a shiny server. -->

<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Welcome to Shiny Server!</title>
<style type="text/css">
body, html {
font-family: Helvetica, Arial, sans-serif;
background-color: #F5F5F5;
color: #114;
margin: 0;
padding: 0;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
#titleBar {
height: 80px;
background-color: #3475b4;
overflow: hidden;
border-bottom: 1px solid #3475b3;
-moz-box-shadow: 0px 0px 10px 3px #BBC;
-webkit-box-shadow: 0px 0px 10px 3px #BBC;
box-shadow: 0px 0px 10px 3px #BBC;
}
#titleBar #container {
margin-top: 14px;
}
#titleBar h1 {
margin: 0 auto .5em auto;
padding: .2em;
color: #EEE;
text-align: center;
}
#intro {
background-color: #DDD;
margin: 1em 1em 0 1em;
padding: .75em;
text-align: center;
border: 1px solid #CCC;
font-size: 18px;
}
#intro p {
margin: .3em 0 .3em 0;
}
#outer-content {
max-width: 910px;
margin-left: auto;
margin-right: auto;
}
#content {
margin: 1em auto 1em auto;
float: left;
}
#main{
margin-right: 350px;
float: left;
line-height: 24px;
}

#shiny{
float: left;
width: 305px;
margin-left: -330px;
padding-left: 20px;
border-left: 1px solid #AAA;
}
#shiny iframe {
margin-top: 30px;
}
.caption{
font-size: 13px;
}
code {
background-color: #E5E5E5;
border: 1px solid #AAA;
-webkit-border-radius: 3px;
-khtml-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
padding: 0 .5em 0 .5em;
}
</style>
</head>
<body>
<div id="titleBar">
<div id="container">
<h1>Welcome to Shiny Server!</h1>
</div>
</div>
<div id="outer-content">
<div id="intro">
<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>
</div>
</div>
</body>
</html>