az_webapp: Deploy a shiny app to Azure

Description Examples

Description

These objects are imported from other packages. Follow the links below to see their documentation.

AzureAppService

az_webapp

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# login
# the equivalent of (interactive) az_login is run outside of R

# subscription
# the azure login action automatically retrieves the enabled subscriptions GitHub Actions

# resource group
az_configure(resource_group = "hoad")
# you can also pass this argument to shiny_deploy_az for the one-call deployment
# you can also set this once and commit the resulting .azure/config
# but this is not easily available during testing, so it's set from R here
# because several apps are deployed below, `name` is set for each of them

# plan
plan <- "hoad"
# there's no way to set a plan default

# deploy shiny app using rocker image
az_configure(name = "hello-shiny")
az_webapp(
  # this image actually includes *more* than necessary
  # for example, it includes shinyserver, but just shiny would suffice
  deployment_container_image_name = "rocker/shiny:4.0.2",
  # above image has no `ENTRYPOINT` and/or `CMD` to start shiny by default.
  # so this `[COMMAND]` must be appended to `docker run`
  startup_file = paste(
    "Rscript",
    # setting shiny options for azure manually
    # equivalent to running shinycaas::shiny_opts_az()
    "-e options(shiny.host='0.0.0.0',shiny.port=as.integer(Sys.getenv('PORT')))",
    # remove getOption call https://github.com/subugoe/shinycaas/issues/37
    "-e shiny::runExample('01_hello',port=getOption('shiny.port'))"
  ),
  plan = plan
)

# deploy shiny app to slot
az_webapp(
  deployment_container_image_name = "rocker/shiny:4.0.2",
  startup_file = paste(
    "Rscript",
    "-e options(shiny.host='0.0.0.0',shiny.port=as.integer(Sys.getenv('PORT')))",
    "-e shiny::runExample('05_sliders',port=getOption('shiny.port'))"
  ),
  plan = plan,
  slot = "sliders" # a more suitable slot name might be "dev" or "staging"
)

# deploy shiny app using private image, here from muggle package
# below env vars and secrets are only available on github actions
if (is_github_actions()) {
  # for an easier way to set these arguments, see the {muggle} package
  az_configure(name = "old-faithful")
  az_webapp(
    deployment_container_image_name = paste0(
      "docker.pkg.github.com/subugoe/shinycaas/oldfaithful", ":",
      ifelse(is_github_actions(), Sys.getenv("GITHUB_SHA"), "latest")
    ),
    plan = plan,
    docker_registry_server_url = "https://docker.pkg.github.com",
    docker_registry_server_user = Sys.getenv("GITHUB_ACTOR"),
    docker_registry_server_password = Sys.getenv("GH_PAT_PKG")
  )
}

# cleanup (necessary for testing)
unlink(".azure", recursive = TRUE)

subugoe/shinycaas documentation built on Nov. 25, 2020, 10:28 p.m.