0

I am trying to read a table from https://www.cdc.gov/nchs/pressroom/sosmap/cancer_mortality/cancer.htm.

I tried two ways, directly reading the csv file and using R package "rvest", but neither worked.

The following is my code:

url = "https://www.cdc.gov/nchs/pressroom/sosmap/cancer_mortality/cancer.htm"

## The csv file link
f = "blob:https://www.cdc.gov/32faf737-1355-4e1a-8b4f-a970820a290b"

# Way #1

rates1 = read.csv(file = f, header=TRUE, sep=",")
rates1

# Way #2

library("rvest")

rates2 = url %>% read_html() %>%   
  html_nodes(xpath='//*[@id="root"]/section/section[2]/div[2]/div[1]/div[2]') %>% 
  html_table(fill=TRUE) %>% 
  .[[1]]

rates2

Error messages:

cannot open file 'blob:https://www.cdc.gov/32faf737-1355-4e1a-8b4f-a970820a290b': No such file or directoryError in file(file, "rt") : cannot open the connection

Sam Chang
  • 61
  • 1
  • 5
  • A URL that was created from a JavaScript Blob can not be converted to a "normal" URL. A blob: URL does not refer to data the exists on the server, it refers to data that your browser currently has in memory, for the current page. It will not be available on other pages, it will not be available in other browsers, and it will not be available from other computers. Therefore it does not make sense, in general, to convert a Blob URL to a "normal" URL. https://stackoverflow.com/questions/14952052/convert-blob-url-to-normal-url – Anakin Skywalker Jun 04 '20 at 04:17
  • Thank you Rookie. Is there any way that R can read the data by other than downloading? – Sam Chang Jun 05 '20 at 22:14
  • What do you mean? Why cannot you just download data and read it with RStudio? – Anakin Skywalker Jun 06 '20 at 03:47
  • I would like to connect the data to a shiny app which should updates as the underlying data are updated. – Sam Chang Jun 07 '20 at 02:31
  • As far as I see, you need to scrape the data (looks like they do not provide API, but ask them additionally), writing a script, which will do it from time to time. Maybe other more advanced people will have better suggestions. – Anakin Skywalker Jun 07 '20 at 05:55

0 Answers0