-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.R
91 lines (67 loc) · 3.17 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
source("helpers.R")
source("global.R")
##1. Map creation using static MTA transit static
##2. Load the file for historical data
## based on scrap of real time MTA API
library(dplyr)
library(lubridate)
library(chron)
# ## Load historical file of real time data records built using Python.
# mtahist = read.csv("data/mta.txt",header=FALSE,stringsAsFactors = FALSE)
# names(mtahist) <- c('tmpSys','TripId','StartDate','Route','alert','j','stop_id','ArrivalTime','Delays')
#
# ## Datafile Setup:
# ## Select only first record for each trainId for each time stamp: j==0
# ## Add direction N or S
# ## Capture and convert time from date stamps
# ## Add col of unique trainID
# mtahist001 = filter(mtahist,j==0)
# mtahist002 = mutate(mtahist001,Direction=substr(mtahist001$stop_id,4,5)) %>%
# mutate(.,TrainId = paste(TripId,StartDate,sep=""))
# mtahist004 = mutate(mtahist002,ArrivalTime=ifelse(ArrivalTime==0,
# as.numeric(ymd_hms(mtahist002$tmpSys, tz = "America/New_York")),
# ArrivalTime))
# mtahist003 = mutate(mtahist004,TmpSys=substr(tmpSys,12,20))
# mtahist003$TmpSys <- chron(times. = mtahist003$TmpSys)
# saveRDS(mtahist003, "mtaHistoricalFeed.rds")
## file was saved in rds format for better results on shiny server
mtafile_cleaned = readRDS("data/mtaHistoricalFeed.rds")
i="ready"
print(i)
#################################################
source("helpers.R")
shinyServer(
function(input, output,session) {
##1. management of outputs for subway and bus map
#finallistbus_react <- reactive({shapesbus_filefct(input$buses,shapes)})
#mapsubways_buses <- reactive({drawmap(input$subways,shapesbus_filefct(input$buses,shapesbuses))})
#output$MTAMap <- renderPlot({mapsubways_buses})
##2. drawing analytics charts using ggplot
## chart Travel Time vs Depart Time
analys_temps <- reactive({input$analys_timeint})
analys_subway <- reactive({input$analys_subw})
analys_delays <-reactive({input$analys_delays})
analys_direction <- reactive({input$analys_direct})
output$Alys <- renderPlot({
line = analys_subway()
if (line==3) {line=c(1,4)}
borneinf = min(analys_temps())
bornesup = max(analys_temps())
graph_trip_time_subway(line,
borneinf,bornesup,
mtafile_cleaned,
analys_delays(),
analys_direction())})
##3. Real time MTA Map
## original script for my own computer
#fileData <- reactiveFileReader(1000, session, 'data/mtaRealTime.txt',read.csv)
#filetmp <- reactive({fileData()
# read.csv("data/mtaRealTime.txt",header=FALSE,stringsAsFactors = FALSE)})
## modified script for nyc data science server
autoInvalidate <- reactiveTimer(10000, session)
reatTime_direct <- reactive({input$real_time_NS})
reatTime_line <- reactive({input$real_time_line})
output$realTimeMap <- renderPlot({autoInvalidate()
graph_real_time(2,reatTime_line(),reatTime_direct())})
}
)