Skip to content

Commit

Permalink
add applications method to list currently deployed applications
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Oct 3, 2013
1 parent 2423f32 commit 0ab6552
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 6 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Collate:
'utils.R'
'lucid.R'
'deployments.R'
'applications.R'
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export(accountInfo)
export(accounts)
export(applications)
export(deploy)
export(removeAccount)
export(setAccountInfo)
37 changes: 37 additions & 0 deletions R/accounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,40 @@ missingAccountErrorMessage <- function(name) {
paste("account named '", name, "' does not exist", sep="")
}

resolveAccount <- function(account) {

# get existing accounts
accounts <- accounts()
if (length(accounts) == 0)
stopWithNoAccount()

# if no account was specified see if we can resolve the account to a default
if (is.null(account)) {
if (length(accounts) == 1)
accounts[[1]]
else
stopWithSpecifyAccount()
}
# account explicitly specified, confirm it exists
else {
if (account %in% accounts)
account
else
stopWithMissingAccount(account)
}
}

stopWithNoAccount <- function() {
stop(paste("You must register an account using setAccountInfo prior to",
"proceeding."), call. = FALSE)
}

stopWithSpecifyAccount <- function() {
stop(paste("Please specify the account name (there are more than one",
"accounts registered on this system)", call. = FALSE))
}

stopWithMissingAccount <- function(account) {
stop(missingAccountErrorMessage(account), call. = FALSE)
}

51 changes: 51 additions & 0 deletions R/applications.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#' List Deployed Applications
#'
#' List all applications currently deployed to ShinyApps for a given account.
#' @param account Account name. If a single account is registered on the
#' system then this parameter can be omitted.
#' @return
#' Returns a data frame with the following columns:
#' \tabular{ll}{
#' \code{id} \tab Unique id for the application\cr
#' \code{name} \tab Name of application \cr
#' \code{url} \tab URL where application can be accessed\cr
#' \code{status} \tab Current status of application. Valid values are \code{pending},
#' \code{deploying}, \code{running}, \code{terminating}, \code{terminated}.
#' }
#' @note To register an account you call the \link{setAccountInfo} function.
#' @examples
#' \dontrun{
#'
#' # list all applications for the default account
#' applications()
#'
#' # list all applications for a specific account
#' applications("myaccount")
#' }
#' @export
applications <- function(account = NULL) {

# resolve account (use default if possible, confirm exists, etc.)
accountInfo <- accountInfo(resolveAccount(account))

# create lucid client and retreive applications
lucid <- lucidClient(accountInfo)
apps <- lucid$applications(accountInfo$accountId)

# convert the list into a data frame with a subset of fields
id <- numeric()
name <- character()
url <- character()
status <- character()
for (app in apps) {
id <- append(id, app$id)
name <- append(name, app$name)
url <- append(url, app$url)
status <- append(status, app$status)
}
data.frame(id = id,
name = I(name),
url = I(url),
status = status)
}
9 changes: 3 additions & 6 deletions R/deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ deploymentTarget <- function(appDir, appName, account) {

# read existing accounts
accounts <- accounts()
if (length(accounts) == 0) {
stop(paste("You must register an account using setAccountInfo prior to",
"deploying an application."), call. = FALSE)
}
if (length(accounts) == 0)
stopWithNoAccount()

# validate account if provided
if (!is.null(account)) {
Expand Down Expand Up @@ -164,8 +162,7 @@ deploymentTarget <- function(appDir, appName, account) {
if (length(accounts) == 1)
createDeploymentTarget(appName, accounts[[1]])
else
stop(paste("Please specify the account which you want to deploy the",
"application to."), call. = FALSE)
stopWithSpecifyAccount()
}

# single existing deployment
Expand Down
39 changes: 39 additions & 0 deletions man/applications.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
\name{applications}
\alias{applications}
\title{List Deployed Applications}
\usage{
applications(account = NULL)
}
\arguments{
\item{account}{Account name. If a single account is
registered on the system then this parameter can be
omitted.}
}
\value{
Returns a data frame with the following columns:
\tabular{ll}{ \code{id} \tab Unique id for the
application\cr \code{name} \tab Name of application \cr
\code{url} \tab URL where application can be accessed\cr
\code{status} \tab Current status of application. Valid
values are \code{pending}, \code{deploying},
\code{running}, \code{terminating}, \code{terminated}. }
}
\description{
List all applications currently deployed to ShinyApps for
a given account.
}
\note{
To register an account you call the \link{setAccountInfo}
function.
}
\examples{
\dontrun{

# list all applications for the default account
applications()

# list all applications for a specific account
applications("myaccount")
}
}

0 comments on commit 0ab6552

Please sign in to comment.