forked from rstudio/shinyapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployments.R
60 lines (45 loc) · 1.87 KB
/
deployments.R
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
saveDeployment <- function(appDir, name, account, bundleId, url) {
deployment <- deploymentRecord(name, account, bundleId, url)
write.dcf(deployment, deploymentFile(appDir, name, account))
invisible(NULL)
}
readDeployments <- function(appDir, nameFilter = NULL, accountFilter = NULL) {
deployments <- deploymentRecord(name = character(),
account = character(),
bundleId = character(),
url = character())
shinyappsDir <- file.path(appDir, "shinyapps")
for (accountDir in file.path(shinyappsDir, list.files(shinyappsDir))) {
# ignore regular files
if (!file.info(accountDir)$isdir)
next
# apply optional account filter
if (!is.null(accountFilter) && !identical(accountFilter,
basename(accountDir)))
next
deploymentFiles <- list.files(accountDir, glob2rx("*.dcf"))
for (deploymentFile in file.path(accountDir, deploymentFiles)) {
deployment <- as.data.frame(read.dcf(deploymentFile),
stringsAsFactors = FALSE)
# apply optional name filter
name <- tools::file_path_sans_ext(basename(deploymentFile))
if (!is.null(nameFilter) && !identical(nameFilter, name))
next
deployments <- rbind(deployments, deployment)
}
}
deployments
}
deploymentFile <- function(appDir, name, account) {
accountDir <- file.path(appDir, "shinyapps", account)
if (!file.exists(accountDir))
dir.create(accountDir, recursive=TRUE)
file.path(accountDir, paste(name, ".dcf", sep=""))
}
deploymentRecord <- function(name, account, bundleId, url) {
data.frame(name = name,
account = account,
bundleId = bundleId,
url = url,
stringsAsFactors = FALSE)
}