Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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