server.R 4 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
  output$file1 <- renderDataTable({
19 20 21
    inFile <- input$file1
    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 50 51 52 53 54
  
  output$lastLoadedNut<- renderText({
    lastCoConUT
    
  })
  
  output$lastLoadedQuest <- renderText({
    lastCoCoQuest
  })
  
Stephanie's avatar
Stephanie committed
55
  #TODO: Getting HEADER out of json to select it
56 57 58 59 60 61 62 63 64
  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({
65 66
    selectInput("in1", "x-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
  })
67
  
68
  output$input_time_y <- renderUI({
69
    selectInput("in1", "y-axis:", as.list(coconut.df),multiple=TRUE, selectize=TRUE) 
70 71
  })
  
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  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) 
  })
87
  
88
  
89
  #TODO: CoCoQuest Output --> Ansätze data[] raus nehmen oder flatten richtig funken
90 91
  output$file2 <- renderDataTable({
    inFile <- input$file2
92 93
    if (is.null(inFile))
      return(NULL)
94
  
95
    
96
    simplifyVector <- c("studyID", "studyName", "description", "tasks$endTime" , "id", "startTime", "endTime")
97
    json_data_quest <- fromJSON(paste(inFile$datapath, sep = ""), simplifyVector = TRUE, simplifyDataFrame = simplifyVector,
98
                                simplifyMatrix = simplifyVector, flatten = TRUE) 
99
    lastLoadedQuest<<-inFile$name
100 101
    print("with simplify: ")
    print(json_data_quest)
102
    
103 104 105 106 107 108 109 110 111 112 113 114 115 116
    ## 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)
117 118
    
  })
119

120
  
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
  #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
138
}