闪亮的服务器部署到shinyapps.io错误

时间:2014-09-21 21:03:19

标签: r shiny shiny-server

我在向shinyapps.io部署应用时遇到问题。

从RStudio(R 3.1.1 / Win64)中运行部署我收到以下消息:

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

然而,在启动应用程序时,我收到一条消息,说“#34;应用程序无法启动" ,并显示以下错误消息:

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

我真的输了什么问题 - 在本地运行应用程序时没有任何问题。

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))})

})

1 个答案:

答案 0 :(得分:0)

httr导入jsonlite和stringr,因此您不需要加载它们。我没有深入研究依赖关系和屏蔽,但是它上面有一个很好的问题/答案HERE,如果一个软件包在掩码方面导入或依赖于其他软件包,那就非常重要。所以我尝试将您在server.R中加载的库更改为:

server.R

 library(shiny)
 library(httr)

 # The rest of your code...
相关问题