Skip to content

Instantly share code, notes, and snippets.

@neerajt
Created December 9, 2018 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neerajt/5a6c73f3571a4e2bbb9777ac4bfeb922 to your computer and use it in GitHub Desktop.
Save neerajt/5a6c73f3571a4e2bbb9777ac4bfeb922 to your computer and use it in GitHub Desktop.
library(shiny)
library(quantmod)
get_symbols <- function(symbol){
symbol_data <- getSymbols(symbol,
src = "yahoo",
auto.assign = FALSE)
names(symbol_data) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted.Close")
symbol_data
}
plot_open_vs_close <- function(symbol_df, symbol){
ggplot(symbol_df) +
geom_point(aes(x=Close, y=Open)) +
theme_classic() +
ggtitle(symbol)
}
#ui
ui <- fluidPage(
titlePanel("Alfreds VIX App"),
sidebarLayout(
sidebarPanel(
textInput("symbol", "Symbol:", "VIX"),
actionButton("search_button", "Go!")
),
mainPanel(
plotOutput("open_vs_close_plot"),
tableOutput("summary")
)
)
)
#server
server <- function(input, output){
symbol_data <- eventReactive(input$search_button, {
get_symbols(input$symbol)
})
output$open_vs_close_plot <- renderPlot(
plot_open_vs_close(symbol_data(), "symbol")
)
output$summary <- renderTable(head(symbol_data()))
}
shiny::shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment