server.R 4.39 KB
Newer Older
Stephanie's avatar
Stephanie committed
1 2 3 4 5 6 7 8 9 10
#
# This is the server logic of a Shiny web application. You can run the 
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
# 
#    http://shiny.rstudio.com/
#

library(shiny)
11
library(jsonlite)
12
library(DT)
Stephanie's avatar
Stephanie committed
13

Stephanie's avatar
Stephanie committed
14 15
server <- function(input, output) {
  set.seed(122)
16
  
17
  #CoConUT Data import and showing into data site 
18 19
  output$nut <- renderDataTable({
    inFile <- input$nut
20 21
    if (is.null(inFile))
      return(NULL)
22
    
23
    #loading CoConUT data
24
    json_data_coco <- fromJSON(paste(inFile$datapath, sep = ""), flatten = TRUE)
25
    coconut.df <<- json_data_coco[["data"]]
26 27 28 29
    
    lastCoConUT <<- inFile$name
    
    
30
    # setting the table style
31 32 33 34 35 36 37 38 39 40 41 42 43
    datatable(
              cbind(coconut.df), 
              options = list(
                searching = TRUE,
                autoWidth = TRUE,
                rownames = FALSE,
                scroller = TRUE,
                scrollX = TRUE,
                scrollY = "500px",
                fixedHeader = TRUE,
                class = 'cell-border stripe'
              )
    )
44
  })
45 46
  
  output$lastLoadedNut<- renderText({
47 48 49
    if (is.null(input$nut))
      return(NULL)
    else lastCoConUT
50 51
    
  })
52

53
  
54 55

  output$questTimes <- renderDataTable({
56 57 58 59
    inFile <- input$quest
    if (is.null(inFile))
      return(NULL)
    
60 61 62 63
    #loading CoCoQuest data
    json_data_quest <<- fromJSON(paste(inFile$datapath, sep = ""), flatten = TRUE)
    #print("json_data_qest")
    #print(json_data_quest)
64
    lastCoCoQuest <<- inFile$name
65
    
66 67
    json_data_quest$unix_starttime <- as.numeric(json_data_quest$startTime)/1000
    json_data_quest$unix_endtime <- as.numeric(json_data_quest$endTime)/1000
68 69 70
    totalStarttime <<- anytime(json_data_quest$unix_starttime)
    totalEndtime <<- anytime(json_data_quest$unix_endtime)
    
71
    
72
    #unix  parsed
73
    
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    dat <- do.call(rbind, json_data_quest$tasks$data)
  
    endtimes <<- c(anytime(dat$endtime/1000))
    tasks <- rep(1:length(json_data_quest$tasks$data), sapply(json_data_quest$tasks$data, nrow))
    #count<<-0
   # y <<-1
   # x<<-1
    #numOfTasks <<- if(tasks[x]!=y)
    #                {
    #                  count<<-count+1
    #                  y<<-y+1
    #                  x<<-x+1
    #}
    #else{x<<-x+1}
   
    together <<- c(tasks, endtimes)
    
    #all <<- matrix(c(tasks,endtimes),byrow=FALSE,nrow=length(tasks))
    all <- rbind(together)
93
    
94
  
95
    #setting the table style
96
    datatable(
97
      cbind(tasks, endtimes),
98
      options = list(
99 100 101 102 103 104 105
        searching = FALSE,
        #autoWidth = TRUE,
        rownames = TRUE,
        #scroller = TRUE,
        #scrollX = TRUE,
       # scrollY = "500px",
       
106
        class = 'cell-border stripe'
107
     )
108 109 110
    )
  })
  
111 112 113 114 115
  #CoCOQuest Data import and showing into data site 
  output$lastLoadedQuest <- renderText({
    if (is.null(input$quest))
      return(NULL)
    else lastCoCoQuest
116
    
117 118 119 120 121 122 123 124
  })
  
  output$totalStarttime <- renderText({
    if (is.null(input$quest))
      return(NULL)
    else as.POSIXct(totalStarttime)
    print(totalStarttime)
  })
125 126
  
  
Stephanie's avatar
Stephanie committed
127
  #TODO: Getting HEADER out of json to select it
128 129 130 131 132 133 134 135 136
  output$input_hist_x <- renderUI({
    selectInput("in1", "x-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
  
  output$input_hist_y <- renderUI({
    selectInput("in1", "y-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
  
  output$input_time_x <- renderUI({
137 138
    selectInput("in1", "x-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
139
  
140
  output$input_time_y <- renderUI({
141
    selectInput("in1", "y-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
142 143
  })
  
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
  output$input_map_x <- renderUI({
    selectInput("in1", "x-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
  
  output$input_map_y <- renderUI({
    selectInput("in1", "y-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
  
  output$input_line_x <- renderUI({
    selectInput("in1", "x-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
  
  output$input_line_y <- renderUI({
    selectInput("in1", "y-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
159
  
160 161
  
  
162
  
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
  #histdata <- rnorm(500)
  
  #output$plot1 <- renderPlot({
  #data <- histdata[seq_len(input$slider)]
  #hist(data)
  #})
  
  ##MAP 
  
  #m <- leaflet()
  #m <- addTiles(m)
  #x=1
  #for(x in 1:2019){
  #m <- addMarkers(m,lng=longitude[x], lat=latitude[x]) #addPolylines does not work
  #x=x+1}
  #m
  #}
Stephanie's avatar
Stephanie committed
180
}