#' scrape yahoo finance news
#'
#' @param ticker a character
#' @return The latest news for \code{ticker}.
#' @examples
#' q_news("aapl")
#' q_news_table("aapl")
#' @section new section:
#' testing a new section
#'
q_news <- function(ticker){
link <- paste0("http://finance.yahoo.com/rss/headline?s=",ticker)
tidyRSS::tidyfeed(link) %>%
select(-(feed_title:feed_language))
}
q_news_table <- function(ticker){
q_news(ticker) %>%
select(title = item_title,
description = item_description,
date = item_date_published,
url = item_link) %>%
mutate(description = ifelse(str_length(description)>=350,paste0(str_sub(description,1,350),"..."),description),
title = paste0("<a href='",url,"' target='_blank'>",title,"</a>")) %>%
select(-url) %>%
datatable(rownames = F,selection = 'single',
escape = F,
class = 'cell-border stripe',
extensions = c('ColReorder','Scroller'),
options = list(colReorder = TRUE,
deferRender = T,
pageLength = 5)) %>%
formatDate(3,'toUTCString') %>%
formatStyle(columns = 1, fontSize = '15px')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.