Created
December 9, 2018 02:23
-
-
Save neerajt/5a6c73f3571a4e2bbb9777ac4bfeb922 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(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