【发布时间】:2016-05-21 20:34:11
【问题描述】:
我有一个 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 文件(每周更新一个不同的 url):“2009-20yy 犯罪数据文件原始数据 (mm/dd /yyyy)"
代码产生错误:
# 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
【问题讨论】: