-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
75 lines (54 loc) · 2.04 KB
/
app.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
library(shiny)
library(plotly)
library(RSelenium)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h4("Choose stock"),
fileInput("files", "Upload CSV File", multiple = FALSE, accept = c(".csv"))
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Input data",
DT::dataTableOutput("input.data")),
tabPanel("Chart",
plotlyOutput("chart"))
)
)
)
)
server <- function(input, output, session) {
observeEvent(input$files, {
stock.input.df <- read.table(input$files$datapath, sep = ";", header = TRUE)
stock.input.df <- stock.input.df[order(stock.input.df$Datum),]
stock.input.df$Datum <- as.Date(stock.input.df$Datum, format = "%Y-%m-%d")
stock.input.df[,-1] <- apply(stock.input.df[,-1], 2, function(x) as.numeric(gsub(",", ".", gsub("\\.", "", x))))
#Add the SMA
for (days in c(30, 100, 200)){
stock.input.df[,paste0("SMA",days)] <- sapply(1:nrow(stock.input.df), function(i) {
SMA <- tryCatch(mean(stock.input.df[(i-days):(i-1),]$Schlusskurs), error=function(e) {NA})
return(SMA)
})
stock.input.df[,paste0("SMA",days)][1] <- NA
}
output$input.data <- DT::renderDataTable(DT::datatable(stock.input.df, options = list(pageLength = 50), rownames = FALSE))
output$chart <- renderPlotly({
plot_ly(data = stock.input.df, x = ~Datum, y = ~Schlusskurs, name = "Powercell", type = "scatter", mode = "line") %>%
add_lines(y = ~ SMA30, name = "SMA30") %>%
add_lines(y = ~ SMA100, name = "SMA100")%>%
add_trace(y = ~ SMA200, name = "SMA200")
})
})
}
shinyApp(ui = ui, server = server)
# https://community.rstudio.com/t/setting-up-rselenium/11622/6
# rs <- rsDriver(port = 4443L,
# browser = "firefox",
# extraCapabilities = list(
# `mox:firefoxOptions` = list(
# binary = "/Applications/Firefox.app/Contents/MacOS/firefox"
# )
# )
# )
# rsc <- rs$client
# rsc$navigate("https://community.rstudio.com/")