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:
- import a specific version of the
rocker/shiny
image - delete all of the example files
- change the working directory to the location where the server will look for apps and
- 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/.
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.