-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
59 lines (44 loc) · 1.6 KB
/
server.R
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
# server.R
library(quantmod)
library(dygraphs)
library(xts)
shinyServer(function(input, output) {
# Update data
stock_data <- reactive({
ticker <- input$symb
data_all <- getSymbols(ticker, src = "yahoo",
from = input$dates[1],
to = input$dates[2],
auto.assign = FALSE)
})
display_data <- reactive({
data <- stock_data()[,6]
if(input$returns) {
ret_data <- diff(log(data))
if(input$duration == "1w") {
data <- apply.weekly(ret_data, sum)
}else if(input$duration == "1mon") {
data <- apply.monthly(ret_data, sum)
}else if(input$duration == "3mon") {
data <- apply.quarterly(ret_data, sum)
}else{
data <- diff(log(ret_data))
}
}
data <- data
})
output$dygraph <- renderDygraph({
datafull<- display_data()
dygraph(datafull, main = "Price Chart") %>%
dyRangeSelector(dateWindow = c((today() - 365), today())) %>%
dyOptions(maxNumberWidth = 20)
# autoplot.zoo(data) +
# theme_bw() +
# ggtitle("Price Chart") +
# labs(x = "Year") +
# scale_color_discrete(name = "Types") +
# scale_y_continuous(name="Price($/Share)")
# chartSeries(data, theme = chartTheme("white"),
# type = "line", log.scale = input$log, TA = NULL)
})
})