-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
93 lines (73 loc) · 2.12 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#NAME: server.R
#FUNC: Display RMarkdown documents and allow upload
#USES: ui.R, server.R
#VER.: 1.0
#HIST: XL initial 02/27/2017
library(shiny)
library(plotly)
source('R/functions.R')
GetLoopData <- function(path){
loopData <- read.csv(path)
return(loopData)
}
# Define server logic required to draw a histogram
shinyServer(function(input, output, session) {
#
LoopInfo <- reactive({
input$refresh # Refresh if button clicked
interval <- as.numeric(input$interval)
# Invalidate this reactive after the interval has passed, so that data is
# fetched again.
invalidateLater(interval * 1000, session)
GetLoopData('data/processed/results.csv') %>% arrange(desc(count))
})
# Get time that vehicles locations were updated
lastUpdateTime <- reactive({
LoopInfo() # Trigger this reactive when vehicles locations are updated
Sys.time()
})
# Number of seconds since last update
output$timeSinceLastUpdate <- renderUI({
# Trigger this every 5 seconds
invalidateLater(1000, session)
p(
class = "text-muted",
"Data refreshed ",
round(difftime(Sys.time(), lastUpdateTime(), units="secs")),
" seconds ago."
)
})
#
output$loopTable <- renderTable({
df <- LoopInfo()
df$flux <- as.character(format(df$flux, scientific = T, digits = 3))
return(head(df, 10))
})
output$rr <- renderValueBox({
df <- LoopInfo()
rrValue <- df[, input$rrtype] %>% RobustRatio()
valueBox(
round(rrValue, 2), "RR", icon = icon("list"), color = "light-blue"
)
})
# output$rrPlot <- renderPlotly({
# df <- LoopInfo()
# rrValue <- df[, input$rrtype] %>% RobustRatio()
#
# now <- as.POSIXlt(Sys.time())
# tm <- seq(0, 600, length.out = nrow())
#
# rrdf <- data.frame(x = now - tm)
#
# x <- now - tm
# y <- rrValue <- df[, input$rrtype] %>% RobustRatio()
# p <- plot_ly(df, x ~x, y = )
# })
# output$countPlot <- renderPlotly({
# df <- LoopInfo()
# df <- head(df, 10)
# p <- plot_ly(df, x = loop, y = count, type = 'bar')
#
# p
# })
})