Shiny Application - From Package Development To Server Deployment
Shiny Application - From Package Development To Server Deployment
Example:
usethis::use_build_ignore("devstuff_history.R")
# Dependencies
usethis::use_package("shiny")
usethis::use_package("DT")
usethis::use_package("stats")
usethis::use_package("graphics")
usethis::use_package("glue")
# For data
usethis::use_data_raw()
# If you want to use the MIT licence, code of conduct, lifecycle badge,
and README
usethis::use_mit_license(name = "ThinkR")
if(app_prod()){
cat("Hey! this is prod mode")
}else{
cat("Hey, this is dev mode :)
!")
}
app_prod
mod_first (we use modules)
app_server and app_ui
run_app
Easier to maintain your app, to organize your project, and to call your code in another
app.
UI Server
app_server app_ui()
run_app.R
-app
-server.R
-ui.R
ui.R:
belgradeapp:::app_ui()
server.R:
belgradeapp:::app_server
run_dev.R:
Visual validation
Allows a better understanding of the customer's request
Better overall vision of the project
It saves time
No need to install your package each time
.rs.api.documentSaveAll()
suppressWarnings(lapply(paste('package:',names(sessionInfo()$otherPkgs),sep=""),
rm(list=ls(all.names = TRUE))
devtools::document('.')
devtools::load_all('.')
options(app.prod=FALSE)
library(shiny)
library(DT)
if (interactive()){
ui <- fluidPage(
mod_thirdUI("test")
)
server <- function(input, output, session) {
r <- reactiveValues(x = "Sepal.Width",y = "Petal.Width", data = iris)
callModule(mod_third,"test", r = r)
}
shinyApp(ui, server)
}
Docker
First thing to do: install Docker!
What is docker?
FROM rocker/r-ver:3.4
RUN apt-get update
RUN apt-get install -y libssl-dev libssh2-1-dev libcurl4-openssl-dev
RUN R -e "install.packages('DT')"
RUN R -e "install.packages('pacman')"
RUN R -e "pacman::p_load(shiny, stats, dplyr, tidyr, magrittr,
ggplot2)"
EXPOSE 3838
CMD ["R", "-e belgradeapp::run_app()"]
Cervan Girard - satRday 2018 - https://thinkr.fr 24 / 34
Build our Shinyapp image
Rprofile.site file:
local({
options(shiny.port = 3838, shiny.host = "0.0.0.0")
})
Then:
cd my-app/
cd thinkr/
FROM openjdk:8-jre
WORKDIR /opt/shinyproxy/
CMD ["java", "-jar", "/opt/shinyproxy/shinyproxy.jar"]
proxy:
port: 8080
authentication: simple
admin-groups: admins
users:
- name: jack
password: password
groups: admins
- name: jeff
password: password
docker:
url: http://localhost:2375
specs:
- id: 01_hello
display-name: Hello Application
description: Application which demonstrates the basics of a Shiny app
container-cmd: ["R", "-e", "shinyproxy::run_01_hello()"]
container-image: openanalytics/shinyproxy-demo
Cervan Girard - satRday 2018 - https://thinkr.fr 28 / 34
Yaml
Let's modify this file:
proxy:
port: 8080
authentication: none
admin-groups: admins
docker:
internal-networking: true
specs:
- id: Belgrade_application
display-name: Belgradeapp
description: Application which demonstrates the basics of a Shiny app
container-cmd: ["R", "-e", "belgradeapp::run_app()"]
container-image: mon_app
container-network: sp-example-net
logging:
file:
shinyproxy.log
### Run it
sudo docker run -d -v /var/run/docker.sock:/var/run/docker.sock --net sp-
example-net -p 8080:8080 mon_ShinyProxy
satRday Paris