I have an issue deploying an app to shinyapps.io.
Running deploy from within RStudio (R 3.1.1/Win64) I get the following message:
Preparing to deploy application...DONE
Uploading application bundle...DONE
Deploying application: 20528...
Waiting for task: 1656427
building: Parsing manifest
building: Installing packages
building: Installing files
building: Pushing image: 54178
deploying: Starting instances
terminating: Stopping old instances
Application successfully deployed to http://littlebig.shinyapps.io/crisis
ShinyApps deployment completed: http://littlebig.shinyapps.io/crisis
However, when launching the app I get a message saying "application failed to start" with the following error message:
Attaching package: ‘shiny’The following object is masked _by_ ‘.GlobalEnv’: tagsError in paste(tags$script(src = "__assets__/sockjs-0.3.min.js"), tags$script(src = "__assets__/shiny-server-pro.js"), : attempt to apply non-functionCalls: local ... eval.parent -> eval -> eval -> eval -> eval -> pasteExecution halted
I'm really lost as to what the problem is - running the app locally works without any issues whatsoever.
ui.R:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Crisis.Net"),
sidebarPanel(
checkboxGroupInput("crisisTags",
label = h4("Tags"),
choices = list(
"Air combat" = "air-combat",
"Armed conflict" = "armed-conflict",
"Suicide bombing" = "suicide-bombing",
"Torture" = "torture"),
selected = NULL)
),
mainPanel(
h4("This app pulls data from the api at crisis.net."),
h5("Select a tag in the list to see the location of the (up to) 500 most recent reported instances."),
htmlOutput("crisisMap")
)
))
server.R
library(httr)
library(jsonlite)
library(stringr)
library(shiny)
query.api <- function(path, ...) {
query <- list(...)
query <- query[!sapply(query, is.null)]
query$apikey <- "xxxxxxxxxxxxxxxxxxxxxxxx"
query.url <- list(
scheme = "http",
hostname = "api.crisis.net",
port = NULL,
path = path,
query = query,
params = NULL,
fragment = NULL,
username = NULL,
password = NULL)
attr(query.url, "class") <- "url"
response <- GET(build_url(query.url))
stop_for_status(response)
return(response)
}
crisisGetItems <- function(before = NULL,
after = NULL,
placeName = NULL,
location = NULL,
distance = NULL,
tags = NULL,
limit = NULL) {
if (!is.null(tags)) tags <- paste(tags, collapse = ",")
if (!is.null(location)) location <- paste(location, collapse = ",")
if (!is.null(before)) before <- format(before, "%Y-%m-%dT%H:%M:%S.000Z")
if (!is.null(after)) after <- format(after, "%Y-%m-%dT%H:%M:%S.000Z")
response <- query.api("item",
before = before,
after = after,
placeName = placeName,
location = location,
distance = distance,
tags = tags,
limit = limit)
response.text <- content(response, as = "text", type = "application/json")
items <- fromJSON(response.text, flatten = TRUE)
lon <- unlist(sapply(items$data$geo.coords, function(x) ifelse(is.null(x), NA, x[1])))
lat <- unlist(sapply(items$data$geo.coords, function(x) ifelse(is.null(x), NA, x[2])))
getTags <- function(x, num) {
if (is.null(x)) {
NA
} else {
if (is.null(x$name[num])) {
NA
} else {
x$name[num]
}
}
}
items <- data.frame(
tag1 = sapply(items$data$tags, getTags, 1),
tag2 = sapply(items$data$tags, getTags, 2),
tag3 = sapply(items$data$tags, getTags, 3),
longitude = lon,
latitude = lat,
src = items$data$`source`,
src.url = items$data$fromURL
)
getLatLon <- function(lat, lon) {
if (is.na(lon) || is.na(lat)) {
NA
} else {
paste(c(lat, lon), collapse = ":")
}
}
items$LatLon <- mapply(getLatLon, items$latitude, items$longitude)
return(items)
}
crisisItems <- subset(crisisGetItems(limit = 500), !is.na(LatLon))
shinyServer(function(input, output) {
output$crisisMap <- renderGvis({
gvisMap(
subset(crisisGetItems(tags = input$crisisTags, limit = 500), !is.na(LatLon)),
"LatLon",
"tag1",
options=list(showTip=TRUE,
showLine=TRUE,
enableScrollWheel=TRUE,
mapType='terrain',
useMapTypeControl=TRUE))})
})
httr imports jsonlite and stringr so you shouldn't need to load those. I haven't looked deeply into dependencies and masking, but there is a great SO question/answer on it HERE and it defiantly matters if a package imports or depends on other packages in terms of masking. So I'd try changing the libraries you load in server.R to:
server.R
library(shiny)
library(httr)
# The rest of your code...