forked from rstudio/shiny-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·80 lines (72 loc) · 2.67 KB
/
deploy
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
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env Rscript
# Usage: ./deploy [app]; if app is missing, all apps under this directory will
# be deployed; otherwise deploy the app(s) specified. Note the shiny-dev-center
# repository must be under the same directory of this shiny-examples repository.
# Please ask [email protected] if you want the credentials for the account
# `gallery` on ShinyApps.io. There are two optional arguments -d and -p, meaning
# deploy the app(s) without publishing to the gallery, and publish without
# deployment.
if (FALSE) {
devtools::install_github('rstudio/shiny')
devtools::install_github('rstudio/rsconnect')
}
# first, sync shiny examples
if (file_test('-d', '../shiny/inst/examples')) {
for (app in list.dirs('../shiny/inst/examples', recursive = FALSE)) {
dir.create(app1 <- sub('^(\\d\\d)_', '0\\1-', basename(app)), showWarnings = FALSE)
file.copy(list.files(app, full.names = TRUE), app1, recursive = TRUE)
}
}
# we reused report.Rmd in example 020, so make a hard link
system2('ln', '-f 016-knitr-pdf/report.Rmd 020-knit-html/')
# a font file that is needed for the example 022
if (!file.exists('022-unicode-chinese/wqy-zenhei.ttc'))
shiny:::download(
'https://github.com/rstudio/shiny-examples/releases/download/v0.10.1/wqy-zenhei.ttc',
'022-unicode-chinese/wqy-zenhei.ttc'
)
# then deploy all apps
library(methods)
library(rsconnect)
# ./deploy [-d] [-p] [001-hello 002-text ...]
apps = commandArgs(TRUE)
only_deploy = FALSE
if ('-d' %in% apps) {
apps = setdiff(apps, '-d')
only_deploy = TRUE
}
only_publish = FALSE
if ('-p' %in% apps) {
apps = setdiff(apps, '-p')
only_publish = TRUE
}
# if no other arguments specified, use all the directories here
if (length(apps) == 0) {
apps = list.dirs(full.names = FALSE, recursive = FALSE)
apps = grep('^[0-9]{3,}', apps, value = TRUE)
} else if (any(i <- !file_test('-d', apps))) {
# you can also `./deploy 001 002` without typing the full app names
if (!all(grep('^[0-9]{3,}$', apps[i])))
stop('Unknown app name(s) ', paste(apps[i], collapse = ', '))
apps = c(
apps[!i],
grep(
paste0('^', paste(apps[i], collapse = '|')),
list.dirs(recursive = FALSE, full.names = FALSE),
value = TRUE
)
)
}
# print the apps that were not successfully deployed
print(apps[unlist(lapply(apps, function(app) {
if (!only_publish) # need deployment
if (inherits(try(deployApp(app, account = 'gallery')), 'try-error'))
return(1)
if (only_deploy) return(0) # no need to publish posts
system(paste(
'../shiny-dev-center/_scripts/import.R',
app,
sprintf('http://gallery.shinyapps.io/%s', app),
sprintf('https://github.com/rstudio/shiny-examples/tree/master/%s', app)
))
})) != 0])