Skip to content

Commit

Permalink
Add configureApp function
Browse files Browse the repository at this point in the history
  • Loading branch information
kippandrew committed Oct 30, 2013
1 parent 6376f0f commit 11cefb8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Collate:
'deployApp.R'
'scaleApp.R'
'terminateApp.R'
'configureApp.R'
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export(removeAccount)
export(scaleApp)
export(setAccountInfo)
export(terminateApp)
export(configureApp)
41 changes: 41 additions & 0 deletions R/configureApp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#' Configure an Application
#'
#' Configure an application currently running on ShinyApps. Note, applications
#' should be re-deployed after being reconfigured. You can bypass application
#' upload by using the upload=FALSE parameter to deployApp.
#' @param appName Name of application to configure
#' @param account Account name. If a single account is registered on the
#' system then this parameter can be omitted.
#' @param size Configure application instance size
#' @param instances Configure number of application instances
#' @examples
#' \dontrun{
#'
#' # set instance size for an application
#' configureApp("myapp", size="xlarge")
#' }
#' @seealso \code{\link{applications}}, \code{\link{deployApp}}
#' @export
configureApp <- function(appName, account = NULL, quiet = FALSE, size = NULL, instances = NULL) {

# resolve target account and application
accountInfo <- accountInfo(resolveAccount(account))
application <- resolveApplication(accountInfo, appName)

# get a list of properties to set
properties <- list()
if (! is.null(size) ) {
properties[[ "containers.template" ]] = size
}
if (! is.null(instances) ) {
properties[[ "containers.count" ]] = instances
}

# set application properties
lucid <- lucidClient(accountInfo)
for (i in names(properties)) {
propertyName <- i
propertyValue <- properties[[i]]
lucid$configureApplication(application$id, propertyName, propertyValue)
}
}
11 changes: 10 additions & 1 deletion R/lucid.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ lucidClient <- function(authInfo) {
json$account <- as.numeric(accountId)
handleResponse(POST_JSON(authInfo, "/applications/", json))
},

configureApplication = function(applicationId, propertyName, propertyValue) {
path <- paste("/applications/", applicationId, "/properties/", propertyName, sep="")
v <- list()
v$value <- propertyValue
handleResponse(PUT_JSON(authInfo, path, v))
},

uploadApplication = function(applicationId, bundlePath) {
path <- paste("/applications/", applicationId, "/upload", sep="")
Expand Down Expand Up @@ -145,7 +152,9 @@ handleResponse <- function(response, jsonFilter = NULL) {
else if (isContentType(response, "text/html")) {

body <- regexExtract(".*?<body>(.*?)</body>.*", response$content)
if (!is.null(body))
if (response$status %in% 200:399)
body
else if (!is.null(body))
reportError(body)
else
reportError(response$content)
Expand Down

0 comments on commit 11cefb8

Please sign in to comment.