Last active
August 5, 2021 19:31
-
-
Save rpkyle/e01e67b1b395291f65b7a584ebe6a93a to your computer and use it in GitHub Desktop.
Dash for R Stock Ticker Sample App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dash) | |
library(dashHtmlComponents) | |
library(dashCoreComponents) | |
library(quantmod) | |
getSymbols(c("Coke" = "COKE", "Tesla" = "TSLA", "Apple" = "AAPL")) | |
app <- Dash$new() | |
app$layout( | |
htmlDiv( | |
list( | |
dccDropdown( | |
id = "stock-dropdown", | |
options = list( | |
list(label = "Coke", value = "COKE"), | |
list(label = "Tesla", value = "TSLA"), | |
list(label = "Apple", value = "AAPL") | |
), | |
value = "COKE" | |
), | |
dccGraph(id = "stock-graph") | |
) | |
) | |
) | |
app$callback(output("stock-graph", "figure"), | |
list(input("stock-dropdown", "value")), | |
function(ticker) { | |
d <- switch(ticker, AAPL = AAPL, TSLA = TSLA, COKE = COKE) | |
list( | |
data = list( | |
list(x = index(d), y = as.numeric(d[, 4])) | |
), | |
layout = list(title = ticker) | |
) | |
} | |
) | |
app$run_server() |
The ticker symbol for Coke is "KO" and not "COKE"
The ticker symbol for Coke is "KO" and not "COKE"
@ashgreat I think it's more accurate to say that "KO" is the NYSE symbol for the Coca-Cola Company, and "COKE" is the NASDAQ symbol for Coca-Cola Bottling Consolidated. "TSLA" and "AAPL" are both NASDAQ symbols, and that's why "COKE" is used here instead.
Thanks for the clarification. I still think this is a strange choice of a company given that it's just an independent bottler (mkt value $3 billion) of the Coca Cola Company (mkt value $256 billion). Anyway it's a trivial thing and I don't want to take away from the actual objective of the application.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python version: https://gist.github.com/rpkyle/b69a4c70bb35b53c1902587a7c3e52dc
Julia version: https://gist.github.com/rpkyle/cedf2b34043362d303ed677f139c8375
F# version: https://gist.github.com/kMutagene/b1af6e4d388dbd04a47a1014ad450593