What the YAML looks like
--- title: "My Document" params: data: file.csv stocks: '["AAPL", "MO", "AMZN"]' html_page: TRUE title: Stock Stuff output: html_document: default pdf_document: default ---
stock_vector <- jsonlite::fromJSON(params$stocks) print(params)
knitr::opts_chunk$set(eval = (length(stock_vector) >= 2), message=FALSE, warning=FALSE )
r params$title
library(tidyquant) library(ggplot2) library(tidyverse)
print(params) stocks <- tq_get(stock_vector) glimpse(stocks) gg <- ggplot(stocks) + aes(x = date, y = close, colour = symbol) + geom_line() print(gg)
stocks %>% select(date, symbol, adjusted) %>% pivot_wider(names_from = symbol, values_from = c( adjusted )) %>% select_if(is.numeric) %>% cor
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.