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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.