server.R 4.7 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 53 54 55
  output$lastLoadedQuest <- renderText({
    lastCoCoQuest
  })
  
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  output$quest <- renderDataTable({
    inFile <- input$quest
    if (is.null(inFile))
      return(NULL)
    
    #loading CoConUT data
    json_data_quest <- fromJSON(paste(inFile$datapath, sep = ""), flatten = TRUE)
    cocoquest.df <<- json_data_quest[["data"]]
    
    lastCoCoQuest <<- inFile$name
    
    
    # setting the table style
    datatable(
      cbind(cocoquest.df), 
      options = list(
        searching = TRUE,
        autoWidth = TRUE,
        rownames = FALSE,
        scroller = TRUE,
        scrollX = TRUE,
        scrollY = "500px",
        fixedHeader = TRUE,
        class = 'cell-border stripe'
      )
    )
  })
  
  #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
116
  #TODO: Getting HEADER out of json to select it
117 118 119 120 121 122 123 124 125
  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({
126 127
    selectInput("in1", "x-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
128
  
129
  output$input_time_y <- renderUI({
130
    selectInput("in1", "y-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
131 132
  })
  
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  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) 
  })
148
  
149 150
  
  
151
  
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  #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
169
}