Jessie J. Q
2019-04-11
library(dplyr)
library(ggplot2)
library(tidyr)
library(GGally)
gafa <- read.csv("C:/Users/JJQ/Documents/data/GAFA Stock Prices.csv", stringsAsFactors = FALSE)
str(gafa)
summary(is.na(gafa))
sub_gafa <- select(gafa, Open:Volume)
sub_gafa1 <- lapply(sub_gafa, function(x)(as.numeric(x)))
sub_gafa2 <- as.data.frame(sub_gafa1)
date <- as.Date(gafa$Date, '%d/%m/%Y')
gafa_stock <- cbind(gafa$Stock, date, sub_gafa2)
colnames(gafa_stock) <- c("Company", "Date", "Open", "High", "Low", "Price", "AdjClose", "Volume" )
library(shiny)
ui <- fluidPage(
titlePanel("GAFA Stock Prices"),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "dataset",
label = "Choose a company:",
choices = c("Amazon", "Apple", "Facebook", "Google")),
dateInput('date',
label = 'Date input: yyyy-mm-dd',
value = Sys.Date()
),
numericInput(inputId = "obs",
label = "Number of observations to view:",
value = 10),
checkboxInput("show_xlab", "Show/Hide X Axis Label", value = TRUE),
checkboxInput("show_ylab", "Show/Hide Y Axis Label", value = TRUE)
),
mainPanel(
plotOutput("plot1"),
tableOutput("view")
)
))
server <- function(input, output) {
datasetInput <- reactive({
switch(input$dataset,
"Apple" = apple2,
"Amazon" = amazon2,
"Facebook" = facebook2,
"Google" = google2)
})
output$view <- renderTable({
filter(datasetInput(), Date1 == input$date)
})
output$plot1 <- renderPlot({
g <- ggplot(gafa_stock, aes(Date, Price, color = Company)) + geom_line() + xlab("Date") + ylab("Price")
print(g)
})
}
shinyApp(ui = ui, server = server)