Using Shiny Server in Docker

[This article was first published on R - datawookie, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A quick note on how to use the Shiny Server Docker image, rocker/shiny.

I’m a big believer in starting with the simplest possible setup, getting that to work and then adding complexity in layers. We’ll start with a simple Shiny application in app.R.

library(shiny)

ui <- fluidPage(
  titlePanel("Example Shiny Application")
)

server <- function(input, output) {
}

shinyApp(ui = ui, server = server)

It really doesn’t get much simpler than that.

We want to wrap that up in a Docker image.

FROM rocker/shiny:4.1.0

RUN rm -rf /srv/shiny-server/*

WORKDIR /srv/shiny-server/

COPY ./app.R ./app.R

The Dockerfile doesn’t do anything fancy:

  1. import a specific version of the rocker/shiny image
  2. delete all of the example files
  3. change the working directory to the location where the server will look for apps and
  4. copy the app onto the image.

You don’t explicitly run the application, just put it into the server folder and the server does the rest. The application will reside at /srv/shiny-server/app.R on the image.

With those two files in place we can build the image, giving it a tag of shiny-in-docker.

docker build -t shiny-in-docker .

That should only take a short while. Then we can run it, exposing the Shiny Server on port 3838.

docker run --rm -p 3838:3838 shiny-in-docker

Once the container has launched you should be able to view the application in a browser at http://127.0.0.1:3838/.

To leave a comment for the author, please follow the link and comment on their blog: R - datawookie.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)