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
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:
and locally intsalled:
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
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 called PORT
with value 80: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.