部署时出现闪亮的应用程序错误,在本地运行(rvest - > html_nodes问题)

时间:2016-05-21 20:34:12

标签: r shiny rvest

我有一个Shiny应用程序从亚特兰大警察局网站下载一个zip文件,并将其解压缩到临时文件。该应用程序在本地运行良好,但当我将其部署到shinyapps.io时,我收到一个错误: could not find function "xpath_combinedselector"

我已将其固定为对R包“rvest”的调用,函数“html_nodes”(使用包“selectr”将CSS选择器转换为XML)。我认为它与Shiny端的版本控制有关,但我对如何修复它感到困惑。

作为参考,犯罪数据下载网站是:http://www.atlantapd.org/crimedatadownloads.aspx我正在使用底部的zip文件(每周更新一次不同的网址):“2009-20yy Crime Data File Raw Data(mm月/日/年)“

代码生成错误:

# load libraries (some of these are used later on in the app, but 
# included here in case they might be the cause)
library(shiny); library(lubridate); library(ggplot2)
library(ggmap); library(RgoogleMaps); library(readr)
library(rvest); library(dplyr)

# Set up temp file to download zip file to
temp <- tempfile()

# Download zip file from location on APD website, to above temp file
download.file(
   read_html("http://www.atlantapd.org/crimedatadownloads.aspx") %>% 
      # THE NEXT LINE IS THE PROBLEM CHILD
      html_nodes("tr:nth-child(15) a") %>% 
      html_attr("href") %>% 
      paste0("http://www.atlantapd.org/", .),
   destfile = temp)

Shiny App错误日志:

2016-05-21T19:47:43.603137+00:00 shinyapps[103450]: Warning: Error in do.call: could not find function "xpath_combinedselector"
2016-05-21T19:47:43.610211+00:00 shinyapps[103450]: Stack trace (innermost first):
2016-05-21T19:47:43.610213+00:00 shinyapps[103450]:     76: do.call
2016-05-21T19:47:43.610214+00:00 shinyapps[103450]:     75: .self$xpath
2016-05-21T19:47:43.610216+00:00 shinyapps[103450]:     74: selector_to_xpath
2016-05-21T19:47:43.610217+00:00 shinyapps[103450]:     73: FUN
2016-05-21T19:47:43.610218+00:00 shinyapps[103450]:     72: lapply
2016-05-21T19:47:43.610221+00:00 shinyapps[103450]:     69: <Anonymous>
2016-05-21T19:47:43.610222+00:00 shinyapps[103450]:     68: mapply
2016-05-21T19:47:43.610223+00:00 shinyapps[103450]:     67: Map
2016-05-21T19:47:43.610224+00:00 shinyapps[103450]:     66: selectr::css_to_xpath
2016-05-21T19:47:43.610225+00:00 shinyapps[103450]:     65: make_selector
2016-05-21T19:47:43.610226+00:00 shinyapps[103450]:     64: node_find_all
2016-05-21T19:47:43.610227+00:00 shinyapps[103450]:     63: xml_find_all.xml_node
2016-05-21T19:47:43.610220+00:00 shinyapps[103450]:     70: tran$css_to_xpath
2016-05-21T19:47:43.610230+00:00 shinyapps[103450]:     60: html_nodes
2016-05-21T19:47:43.610219+00:00 shinyapps[103450]:     71: sapply
2016-05-21T19:47:43.610232+00:00 shinyapps[103450]:     58: withVisible
2016-05-21T19:47:43.610233+00:00 shinyapps[103450]:     57: freduce
2016-05-21T19:47:43.610234+00:00 shinyapps[103450]:     56: _fseq
2016-05-21T19:47:43.610235+00:00 shinyapps[103450]:     55: eval
2016-05-21T19:47:43.610236+00:00 shinyapps[103450]:     54: eval
2016-05-21T19:47:43.610237+00:00 shinyapps[103450]:     53: withVisible
2016-05-21T19:47:43.610238+00:00 shinyapps[103450]:     52: %>%
2016-05-21T19:47:43.610231+00:00 shinyapps[103450]:     59: function_list[[k]]
2016-05-21T19:47:43.610229+00:00 shinyapps[103450]:     61: html_nodes.default
2016-05-21T19:47:43.610228+00:00 shinyapps[103450]:     62: xml2::xml_find_all
2016-05-21T19:47:43.610242+00:00 shinyapps[103450]:      9: tryCatchList
2016-05-21T19:47:43.610243+00:00 shinyapps[103450]:      8: tryCatch
2016-05-21T19:47:43.610244+00:00 shinyapps[103450]:      7: connect$retry
2016-05-21T19:47:43.610245+00:00 shinyapps[103450]:      6: eval
2016-05-21T19:47:43.610246+00:00 shinyapps[103450]:      5: eval
2016-05-21T19:47:43.610238+00:00 shinyapps[103450]:     13: runApp
2016-05-21T19:47:43.610247+00:00 shinyapps[103450]:      3: eval
2016-05-21T19:47:43.610239+00:00 shinyapps[103450]:     12: fn
2016-05-21T19:47:43.610240+00:00 shinyapps[103450]:     11: doTryCatch
2016-05-21T19:47:43.610241+00:00 shinyapps[103450]:     10: tryCatchOne
2016-05-21T19:47:43.610415+00:00 shinyapps[103450]: Error in do.call(method, list(parsed_selector)) : 
2016-05-21T19:47:43.610248+00:00 shinyapps[103450]:      2: eval.parent
2016-05-21T19:47:43.610247+00:00 shinyapps[103450]:      4: eval
2016-05-21T19:47:43.610249+00:00 shinyapps[103450]:      1: local

1 个答案:

答案 0 :(得分:1)

问题是为thez提供参数时的lazyeval方法 html_node功能。此函数只有一个参数,css或xpath。

如果你没有指定参数的类型,在你的情况下是一个css选择器,参数将被视为xpath (这就是你得到的原因) error:could not find function "xpath_combinedselector")。因此,为了确保闪亮的服务器 - 在部署应用程序时 - 识别您提供的参数类型,您应该指定为html_nodes参数,如下所示:

 html_nodes(css="tr:nth-child(15) a")