LearnR tutorial, and scripts to deploy on the cloud.
You should have R and the 'learnr' library installed.
-
Modify the LearnR.Rmd file with your tutorial
-
Make the file 'shiny.sh' executable:
chmod +x shiny.sh
- Run ./shiny.sh
Where shiny.sh file is:
#!/bin/bash
Rscript run.R
and run.R (the file "LearnR.Rmd" can be any general learnr tutorial markdown, make sure it is in your working directory):
rmarkdown::run(file = "LearnR.Rmd",
shiny_args = list(port = 1111,host = "0.0.0.0"))
The following instructions assume that you have:
- Docker Hub Account
- Azure subscription
and locally intsalled:
- Docker
- Azure CLI
From a command line run the following commands. Values in <> should be replaced with respect to the set up and project description.
az group create \
--name <project-resource-group> \
--location uksouth
az storage account create \
--name <project> \
--resource-group <project-resource-group> \
--location uksouth \
--sku Standard_LRS \
--encryption blob
az storage account keys list \
--account-name <project> \
--resource-group <project-resource-group> \
--output table
export AZURE_STORAGE_ACCOUNT=<project>
export AZURE_STORAGE_ACCESS_KEY="<one of the key values from the previous table>"
az storage container create --name <projectcontainer>
setting: storage account name, key, and the name of the container.
project.dockerfile must include the following lines:
ENV AZURE_STORAGE_ACCOUNT <project (from 1.2.)>
ENV AZURE_STORAGE_ACCESS_KEY "<one of the key values from the previous table (from 1.3.1.)>"
ENV AZURE_CONTAINER <projectcontainer (from 1.4.)>
An example of a project.dockerfile
FROM r-base:3.5.1
# install R, and setup CRAN mirror
RUN apt-get update && apt-get install -y software-properties-common pandoc gnupg
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
RUN echo "r <- getOption('repos'); r['CRAN'] <- 'http://cran.us.r-project.org'; options(repos = r);" > ~/.Rprofile
# install needed R packages
RUN Rscript -e "install.packages('shiny')"
RUN Rscript -e "install.packages('shinythemes')"
RUN Rscript -e "install.packages('ggplot2')"
RUN Rscript -e "install.packages('learnr')"
RUN Rscript -e "install.packages('tools')"
RUN Rscript -e "install.packages('rmarkdown')"
ADD . LearnRWebApp
WORKDIR LearnRWebApp
# azure config
ENV AZURE_STORAGE_ACCOUNT acountname
ENV AZURE_STORAGE_ACCESS_KEY ====key====
ENV AZURE_CONTAINER containername
# expose R Shiny port
EXPOSE 1111
CMD ["./shiny.sh"]
docker build -t <dockerhub_username>/<project_dashboard>:latest -f <project.dockerfile> .
docker push <dockerhub_username>/<project_dashboard>:latest
- Login to the Azure portal https://portal.azure.com
- On the left hand bar, click "App Services".
- Click "+ Add" at the top, then choose "Web App", then "Create" on the bottom right.
- On the "Create" form, choose an app name (e.g. ) - this will form the URL for your app, so needs to be unique. Choose a subscription and Resource Group (creating one if necessary), and for "OS" choose "Docker". Then click on "Configure container".
- In the "Container Settings" choose "Docker Hub" as the image source, then "Public" or "Private" depending on the settings of your docker hub repo. (If it is "Private" you will also need to provide your docker hub login details.)
- Then click "Create" back on the "Web App create" section. It will take a few minutes to deploy, and after that it will be visible from the "App Services" link on the left of the Azure portal. If you click on the app here you'll get the info for it, including the URL, which should be https:///azurewebsites.net
-
Finally, we need to configure the app to use the correct port. Go to the "Application Settings" of the app in the Azure portal, click
+ Add new setting
and add a setting calledPORT
with value80:1111
. Then go back to the "Overview" and restart the app using the button at the top. -
In practice, even after the Azure portal said it was available and healthy, it can take a long time (about 5 mins) to respond the first time, as the docker image needs to be downloaded and deployed, but after that it should be more responsive.