Skip to content

Instantly share code, notes, and snippets.

@msummersgill
Last active February 7, 2018 11:26
Show Gist options
  • Save msummersgill/4d3a6a185b1e1eeeb2ff58c6c888475d to your computer and use it in GitHub Desktop.
Save msummersgill/4d3a6a185b1e1eeeb2ff58c6c888475d to your computer and use it in GitHub Desktop.
library(shiny)
library(BatchGetSymbols)
ui <- fluidPage(
textInput('stock','stock',"GE"),
sliderInput('length', 'length', min = 1, max = 100, value = 50),
dataTableOutput('my_table')
)
server <- function(input, output, session) {
l.out <- reactive({
BatchGetSymbols(tickers = input$stock,
first.date = Sys.Date() - as.integer(input$length),
last.date = Sys.Date())
})
stock_info <- reactive({
l.out()$df.tickers
})
stock_info()$return <- reactive({
rep(0, length(stock_info()$ref.date))
})
stock_info()$return <- reactive({
for (i in 2:length(stock_info()$ref.date)){
stock_info()$return[i] <- ((stock_info()$price.close[i] -
stock_info()$price.close[i - 1]) / stock_info$price.close[i - 1])
}
})
output$my_table <- renderDataTable({
stock_info()
})
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment