knitr::opts_chunk$set(echo = FALSE)
library(tidyquant) library(dplyr) library(ggplot2) library(plotly) library(glue) library(DT) library(RedditExtractoR) library(gt)
The goal of evInvestment ("Electric Vehicle Investment") is to take a quick glance of publicly EV companies (you can review any stock) traded companies key metrics in the following areas:
NIO <- tq_get("NIO") NIO <- NIO %>% dplyr::mutate(RedGreenDay = ifelse(close >= open, "+ DAY", "- DAY")) p1Ann <- list( text = ("NIO Price History"), xref = "paper", yref = "paper", yanchor = "bottom", xanchor = "center", align = "center", x = 0.5, y = 1, showarrow = FALSE ) p1 <- plotly::plot_ly(NIO, x = ~ date, y = ~ close, mode = "line") %>% layout(annotations =p1Ann, yaxis = list(title = "Price"), xaxis = list(title = "Date"), rangeselector = list( buttons = list( list( count = 3, label = "3 mo", step = "month", stepmode = "backward"), list( count = 6, label = "6 mo", step = "month", stepmode = "backward"), list( count = 1, label = "1 yr", step = "year", stepmode = "backward"), list( count = 1, label = "YTD", step = "year", stepmode = "todate"), list(step = "all"))), rangeslider = list(type = "date") ) p1
p2Ann <- list( text = ("NIO Price Distribution"), xref = "paper", yref = "paper", yanchor = "bottom", xanchor = "center", align = "center", x = 0.5, y = 1, showarrow = FALSE) p2 <- plotly::plot_ly(NIO, x = ~ close, mode = "histogram") %>% layout(annotations = p2Ann, yaxis = list(title = "Frequency"), xaxis = list(title = "Price") ) p2
p3Ann <-list( text = ("NIO Price/Volume"), xref = "paper", yref = "paper", yanchor = "bottom", xanchor = "center", align = "center", x = 0.5, y = 1, showarrow = FALSE) p3 <- plotly::plot_ly( NIO, x = ~ volume, y = ~ close, type = "scatter", color = ~ RedGreenDay, colors = c("red", "dark green"), opacity = .5 ) %>% layout(annotations = p3Ann, yaxis=list(title= "Price") ,xaxis = list(title = "Volume")) p3
p4Ann <-list( text = ("NIO Volume/Date"), xref = "paper", yref = "paper", yanchor = "bottom", xanchor = "center", align = "center", x = 0.5, y = 1, showarrow = FALSE) p4 <- plotly::plot_ly( NIO, x = ~ date, y = ~ volume, type = "scatter", color = ~ RedGreenDay, colors = c("red", "dark green"), opacity = .5 ) %>% layout(annotations = p4Ann, yaxis=list(title= "Volume"), xaxis = list(title = "Date")) p4
NIOsentiment <- reddit_urls( search_terms = "NIO STOCK", page_threshold = 1, sort_by = "new", wait_time = 3, subreddit = "wallstreetbets" ) NIOdata <- NIOsentiment %>% mutate(date = dmy(date)) NIOdata <- NIOdata %>% select(date, title, URL) %>% arrange(desc(date)) render <- c( "function(data, type, row){", " if(type === 'display'){", " var a = '<a href=\"' + row[3] + '\">' + data + '</a>';", " return a;", " } else {", " return data;", " }", "}" ) DT::datatable(NIOdata, escape = FALSE, filter = list(position = "top"), options = list( columnDefs = list( list(targets = 2, render = JS(render)), list(targets = 3, visible = FALSE)))) %>% DT::formatStyle(columns = colnames(NIOdata), fontSize = '50%') # reference [How to filter columns containing hyperlinks in r DT](https://stackoverflow.com/questions/45596315/how-to-filter-columns-containing-hyperlinks-in-r-dt)
view mycode{target="_blank"}
view website{target="_blank"}
view website{target="_blank"}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.