server.R 5.21 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 47 48 49
  
  output$lastLoadedNut<- renderText({
    lastCoConUT
    
  })
50 51

  #CoCOQuest Data import and showing into data site 
52
  output$lastLoadedQuest <- renderText({
53
    
54 55
  })
  
56 57 58


  output$questTimes <- renderDataTable({
59 60 61 62
    inFile <- input$quest
    if (is.null(inFile))
      return(NULL)
    
63 64 65 66 67
    #loading CoCoQuest data
    json_data_quest <<- fromJSON(paste(inFile$datapath, sep = ""), flatten = TRUE)
    #print("json_data_qest")
    #print(json_data_quest)
    #lastCoCoQuest <<- inFile$name
68
    
69 70 71 72
    json_data_quest$unix_starttime <- as.numeric(json_data_quest$startTime)/1000
    json_data_quest$unix_endtime <- as.numeric(json_data_quest$endTime)/1000
    starttime <- anytime(json_data_quest$unix_starttime)
    endtime <- anytime(json_data_quest$unix_endtime)
73
    
74 75 76 77 78
   
    #unix  parsed
    questTimes <<- c(starttime ,endtime)
    print("questTime")
    print(questTimes)
79
    
80 81 82 83 84 85 86
    mat <- matrix(questTimes,1,2)
    #mat <- matrix(as.Date(questTimes),1,2)
    
    print("mat")
    print(mat)
    colnames(mat)<-c("Starttime", "Endtime")
    #setting the table style
87
    datatable(
88
      cbind(mat),
89
      options = list(
90 91 92 93 94 95 96
        searching = FALSE,
        #autoWidth = TRUE,
        rownames = TRUE,
        #scroller = TRUE,
        #scrollX = TRUE,
       # scrollY = "500px",
       
97
        class = 'cell-border stripe'
98
     )
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    )
  })
  
  #TODO: CoCoQuest Output --> Ansätze data[] raus nehmen oder flatten richtig funken
  ##output$file2 <- renderDataTable({
   # inFile <- input$file2
    #if (is.null(inFile))
     # return(NULL)
    
    
    #simplifyVector <- c("studyID", "studyName", "description", "tasks$endTime" , "id", "startTime", "endTime")
    #json_data_quest <- fromJSON(paste(inFile$datapath, sep = ""), simplifyVector = TRUE, simplifyDataFrame = simplifyVector,
     #                           simplifyMatrix = simplifyVector, flatten = TRUE) 
    #lastLoadedQuest<<-inFile$name
    #print("with simplify: ")
    #print(json_data_quest)
    
    ## ANSATZ zum rauslesen der Times: --> not working now
    
    #questLength <<- length(json_data_quest)
    #print("length")
    #print(questLength)
    #data <- c(json_data_quest$tasks[[1]]$`data`[[1]]$endtime, json_data_quest$tasks[[1]]$`data`[[2]]$endtime, json_data_quest$tasks[[1]]$startTime, json_data_quest$tasks[[1]]$endTime, json_data_quest$tasks[[2]]$`data`[[1]]$endtime, json_data_quest$tasks[[2]]$`data`[[2]]$endtime, json_data_endtime$tasks[[2]]$`data`[[3]]$endtime)
    #data<-c(json_data_quest$tasks[[1]]$startTime, json_data_quest$tasks[[1]]$endTime, json_data_quest$tasks[[2]]$startTime, json_data_quest$tasks[[2]]$endTime )
    
    #x<<-0
    #for(x in x:questLength)
    #{data<<-c(json_data_quest$tasks[[x]]$startTime, json_data_quest$tasks[[x]]$endTime)
    #x=x+1}
    #print("data: ")
    #print(data)
    
  ##})
  
  
Stephanie's avatar
Stephanie committed
134
  #TODO: Getting HEADER out of json to select it
135 136 137 138 139 140 141 142 143
  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({
144 145
    selectInput("in1", "x-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
146
  
147
  output$input_time_y <- renderUI({
148
    selectInput("in1", "y-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
149 150
  })
  
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
  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) 
  })
166
  
167 168
  
  
169
  
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
  #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
187
}