Repository navigation
Expand file tree
/
Copy pathapp.R
More file actions
66 lines (58 loc) · 1.34 KB
/
Copy pathapp.R
File metadata and controls
66 lines (58 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Load packages ----
library(shiny)
library(bslib)
library(quantmod)
# Source helpers ----
source("helpers.R")
# User interface ----
ui <- page_sidebar(
title = "stockVis",
sidebar = sidebar(
helpText(
"Select a stock to examine.
Information will be collected from Yahoo finance."
),
textInput("symb", "Symbol", "SPY"),
dateRangeInput(
"dates",
"Date range",
start = "2013-01-01",
end = as.character(Sys.Date())
),
br(),
br(),
checkboxInput(
"log",
"Plot y axis on log scale",
value = FALSE
),
checkboxInput(
"adjust",
"Adjust prices for inflation",
value = FALSE
)
),
card(
card_header("Price over time"),
plotOutput("plot")
)
)
# Server logic
server <- function(input, output) {
dataInput <- reactive({
getSymbols(input$symb, src = "yahoo",
from = input$dates[1],
to = input$dates[2],
auto.assign = FALSE)
})
finalInput <- reactive({
if (!input$adjust) return(dataInput())
adjust(dataInput())
})
output$plot <- renderPlot({
chartSeries(finalInput(), theme = chartTheme("white"),
type = "line", log.scale = input$log, TA = NULL)
})
}
# Run the app
shinyApp(ui, server)