diff --git a/DESCRIPTION b/DESCRIPTION index e8bca65..9099b9a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,3 +25,4 @@ Collate: 'deployApp.R' 'scaleApp.R' 'terminateApp.R' + 'configureApp.R' \ No newline at end of file diff --git a/NAMESPACE b/NAMESPACE index 316a9c7..640ac73 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,3 +7,4 @@ export(removeAccount) export(scaleApp) export(setAccountInfo) export(terminateApp) +export(configureApp) \ No newline at end of file diff --git a/R/configureApp.R b/R/configureApp.R new file mode 100644 index 0000000..28de4d5 --- /dev/null +++ b/R/configureApp.R @@ -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) + } +} diff --git a/R/lucid.R b/R/lucid.R index fd32776..62469b2 100644 --- a/R/lucid.R +++ b/R/lucid.R @@ -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="") @@ -145,7 +152,9 @@ handleResponse <- function(response, jsonFilter = NULL) { else if (isContentType(response, "text/html")) { body <- regexExtract(".*?(.*?).*", response$content) - if (!is.null(body)) + if (response$status %in% 200:399) + body + else if (!is.null(body)) reportError(body) else reportError(response$content)