Skip to content

Instantly share code, notes, and snippets.

@rpkyle
Last active August 5, 2021 19:31
Show Gist options
  • Save rpkyle/e01e67b1b395291f65b7a584ebe6a93a to your computer and use it in GitHub Desktop.
Save rpkyle/e01e67b1b395291f65b7a584ebe6a93a to your computer and use it in GitHub Desktop.
Dash for R Stock Ticker Sample App
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()
@ashgreat
Copy link

The ticker symbol for Coke is "KO" and not "COKE"

@rpkyle
Copy link
Author

rpkyle commented Jun 22, 2021

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.

@ashgreat
Copy link

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