server.R 17.3 KB
Newer Older
Stephanie's avatar
Stephanie committed
1 2

library(shiny)
3 4 5 6 7 8 9 10 11 12 13 14 15
library(jsonlite)       # to handle the json file data correctly
library(DT)             # to render the data-tables correctely 
#library(webshot)       # corrently not in use should work for the downloadbutton
#library(knitr)         # supposed to do Dynamic Report Generation in R
library(leaflet)        # to render the map --> instead of google
#library(mapview)       # not in use but could be used for map instead of leaflet 
#library(ggplot2)       # not in use but for rendering plots
library(timevis)        # for rendering the fancy timeline
#library(plotly)        # not in use but for rendering plots
library(Cairo)          #creating the pdf for download
library(grDevices)      # also necessary for the download
library(anytime)        # for correctly parsing unixtimestamps into readable date and time formats
library(shinydashboard) # creating the structure / dashboard structure-items
16

17
server <- function(input, output, session) {
Stephanie's avatar
Stephanie committed
18
  set.seed(122)
19
  
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
20 21
  
  #Continue to data page  
22 23 24
  observeEvent(input$dataSite, {
    
    updateTabItems(session, "tabs",selected = "data")
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
25
    
26
  })
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
27
  #DATA PAGE
28
  
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
29
  
30
  
31
  #CoConUT Data import 
32 33
  output$nut <- renderDataTable({
    inFile <- input$nut
34 35
    if (is.null(inFile))
      return(NULL)
36
    
37
    #loading CoConUT data
38
    json_data_coco <- fromJSON(paste(inFile$datapath, sep = ""), flatten = TRUE)
39
    print("1")
40
    coconut.df <<- json_data_coco[["data"]]
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
41
    
42
    lastCoConUT <<- inFile$name
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
43
    #print("coconut:")
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
44
    
45
    #coconut.df$timestamp <- format(coconut.df$timestamp, format="%d-%B-%Y %H:%M:%S")
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
46
    
47
    
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
48
    #print(coconut.df)
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 92 93 94 95 96 97 98 99
    if(is.null(coconut.df$timestamp)){}
    else{unixTime<<-coconut.df$timestamp}
    
    if(is.null(coconut.df$gps.latitude)){}
    else{latitude<<-coconut.df$gps.latitude}
    
    if(is.null(coconut.df$gps.longitude)){}
    else{longitude<<-coconut.df$gps.longitude}
    
    if(is.null(coconut.df$gps.speed)){}
    else{speed<<-coconut.df$gps.speed}
    
    if(is.null(coconut.df$gps.accuracy)){}
    else{gpsAcc<<-coconut.df$gps.accuracy}
    
    if(is.null(coconut.df$light.lux)){}
    else{lux<<-coconut.df$light.lux}
    
    if(is.null(coconut.df$acc.coordinates)){}
    else{accCoord<<-coconut.df$acc.coordinates}
    
    if(is.null(coconut.df$acc.accuracy)){}
    else{accAcc<<-coconut.df$acc.accuracy}
    
    if(is.null(coconut.df$bluetooth.numOfBTDevices)){}
    else{bluetooth<<-coconut.df$bluetooth.numOfBTDevices}
    
    if(is.null(coconut.df$ble.bpm)){}
    else{bleBpm<<-coconut.df$ble.bpm}
    
    if(is.null(coconut.df$ble.bpmlist)){}
    else{bleBpmList<<-coconut.df$ble.bpmlist}
    
    if(is.null(coconut.df$ble.hrv)){}
    else{bleHrv<<-coconut.df$ble.hrv}
    
    if(is.null(coconut.df$ble.hrvlist)){}
    else{bleHrvList<<-coconut.df$ble.hrvlist}
    
    if(is.null(coconut.df$activity.name)){}
    else{activityName<<-coconut.df$activity.name}
    
    if(is.null(coconut.df$activity.confidence)){}
    else{activityConf<<-coconut.df$activity.confidence}
    
    if(is.null(coconut.df$screen.status)){}
    else{screenstatus<<-coconut.df$screen.status}
    
    if(is.null(coconut.df$interaction.touch)){}
    else{touch<<-coconut.df$interaction.touch}
    
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
100 101
    
    
102
    # setting the table style
103
    datatable(
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
104 105 106 107 108 109 110 111 112 113 114
      cbind(coconut.df), 
      options = list(
        searching = TRUE,
        autoWidth = TRUE,
        rownames = FALSE,
        scroller = TRUE,
        scrollX = TRUE,
        scrollY = "500px",
        fixedHeader = TRUE,
        class = 'cell-border stripe'
      )
115
    )
116
  })
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
117 118 119 120 121 122 123
  #last coconut_name
  output$lastLoadedNut<- renderText({
    if (is.null(input$nut))
      return(NULL)
    else lastCoConUT
  })
  
124 125
  #CoCoQuest Data import
  output$quest <- renderDataTable({
126 127 128 129
    inFile <- input$quest
    if (is.null(inFile))
      return(NULL)
    
130 131
    #loading CoCoQuest data
    json_data_quest <<- fromJSON(paste(inFile$datapath, sep = ""), flatten = TRUE)
132
    
133
    lastCoCoQuest <<- inFile$name
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
134
    totalST <<- c(anytime(as.numeric(json_data_quest$startTime)/1000))
135 136
    print(json_data_quest)
    
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
137
    
138
    #unix  parsed
139
    dat <- do.call(rbind, json_data_quest$tasks$data)
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
140
    
141
    endtimes <<- c(dat$endtime)
142
    
143
    parsedEndtimes <<- anytime(endtimes/1000)
144 145
    #endtimes <<- format(dat$endtime, format="%d-%B-%Y %H:%M:%S")
    print("endtime quest")
146
    print(parsedEndtimes)
147
    tasks <- rep(1:length(json_data_quest$tasks$data), sapply(json_data_quest$tasks$data, nrow))
148 149
    #questions 
    #print("Questions:", questions)
150
    together <<- c(tasks, endtimes)
151 152
    print("together")
    print(together)
153
    all <- rbind(together)
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
154
    
155
    #setting the table style
156
    datatable(
157
      cbind(tasks, endtimes),
158
      options = list(
159 160
        searching = FALSE,
        rownames = TRUE,
161
        class = 'cell-border stripe'
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
162
      )
163 164
    )
  })
165 166 167 168 169 170 171
  
  #last cocoquest_name
  output$lastLoadedQuest <- renderText({
    if (is.null(input$quest))
      return(NULL)
    else lastCoCoQuest
  })
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
172
  
173
  #cocoQuest Starttime
174 175 176
  output$totalStarttime <- renderText({
    if (is.null(input$quest))
      return(NULL)
177
    else {
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
178
      format(totalST, format="%d-%B-%Y %H:%M:%S")
179 180
      
    }
181
  })
182
  
183 184
  #Continue to view page  
  observeEvent(input$viewSite, {
185
    
186
    updateTabItems(session, "tabs",selected = "views")
187 188 189
    
  })
  
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
190
  #View PAGE
191 192
  
  #Title Input
193
  output$title <- renderText({ input$title })
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
194
  
195
  #BARCHART selectinputs
196
  output$input_hist_x <- renderUI({
197
    if (is.null(input$nut))
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
198
      return(NULL)
199 200
    selectInput("bar_x", "x-axis:", choices = colnames(coconut.df)) 
    })
201 202
  
  output$input_hist_y <- renderUI({
203 204
    if (is.null(input$nut))
      return(NULL)
205 206
    selectInput("bar_y", "y-axis:", choices = colnames(coconut.df)) 
    })
207
  
208
  
209
  #TIMELINE selectinput--> do not need it
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
210
  
211 212 213 214 215 216 217 218 219 220 221 222
  # output$input_time_data <- renderUI({
  #   if (is.null(input$nut))
  #     return(NULL)
  #   selectInput("input_time_data", "x-axis:", choices = colnames(coconut.df))
  # })
  # 
  # output$input_time_y <- renderUI({
  #   if (is.null(input$nut))
  #     return(NULL)
  #   selectInput("in4", "y-axis:", cbind("unixTime", "longitude", "latitude", "speed", "gps.acc","lux", "light.acc","acc.coordinates", "acc.acc","bluetooth","ble.bpm","ble.bpmlist","ble.hrv","ble.hrvlist","activity.name", "acctivity.confidence","screen.status" ,"touch"),multiple=TRUE, selectize=TRUE) 
  # })
  
223
  #LINECHART selectinput x
224
  output$input_line_x <- renderUI({
225 226
    if (is.null(input$nut))
      return(NULL)
227
    selectInput("line_x", "x-axis", choices=colnames(coconut.df))  
228 229
  })
  
230
  #LINECHART selectinput y
231
  output$input_line_y <- renderUI({
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
232 233
    if (is.null(input$nut))
      return(NULL)
234 235
    selectInput("line_y", "y-axis", choices=colnames(coconut.df))  })
  
236
  
237
  #SCATTERPLOT selectinput x
238
  output$input_scat_x <- renderUI({
239
    if (is.null(input$nut))
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
240
      return(NULL)
241
    selectInput("scat_x", "x-axis", choices=colnames(coconut.df))  
242 243
  })
  
244
  #SCATTERPLOT selectinput y
245
  output$input_scat_y <- renderUI({
246 247
    if (is.null(input$nut))
      return(NULL)
248
    selectInput("scat_y", "y-axis", choices=colnames(coconut.df))  
249
  })
250
  
251
  #BOXPLOT selectinput x
252
  output$input_box_x <- renderUI({
253 254
    if (is.null(input$nut))
      return(NULL)
255
    selectInput("box_x", "data", choices=colnames(coconut.df))  
256 257
  })
  
258
  #BOXPLOT selectinput y
259
  output$input_box_y <- renderUI({
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
260
    if (is.null(input$nut))
261
      return(NULL)
262
    selectInput("box_y", "y-axis", choices=colnames(coconut.df))  
263
  })
264
  
265
  
266 267 268 269 270 271
  #MAP selectinput
  output$input_map <- renderUI({
    if (is.null(input$nut))
      return(NULL)
    selectInput("map_data", "data", choices=colnames(coconut.df))  
  })
272 273
  
  
274 275
  #Continue to dashboard page  
  observeEvent(input$dashboardSite, {
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
276
    
277
    updateTabItems(session, "tabs",selected = "dashboard")
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
278
    
279
  })
280
  
281
  plotCounter <<- 0
282 283 284 285 286 287
  plotname <<- paste("plot", plotCounter, sep="")
  xplotname<<- paste("x",plotname,sep="")
  yplotname<<-paste("y",plotname, sep="")
  
  #TODO: Multiple charts. ADD BARCHART BUTTON
  #BARCHART box insert
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
288 289
  observeEvent(input$check_hist, {
    
290
    plotname<<-paste("plot", plotCounter, sep="")
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
291
    plotCounter<<-plotCounter+1
292 293
    xplotname<<- paste("x",plotname,sep="")
    yplotname<<-paste("y",plotname, sep="")
294 295 296 297
    
    print(plotCounter)
    print(plotname)
   
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
298 299 300
    insertUI(
      
      selector= "#viewpanel", #wo will ichs hinhaben
301 302
      ui= box(  width = 12,
                title="Barchart",
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
303 304 305
                status= "warning",
                solidHeader = TRUE,
                collapsible = TRUE,
306 307
                 selectInput(xplotname, "x-axis", choices=colnames(coconut.df)),
                 selectInput(yplotname, "y-axis", choices=colnames(coconut.df)),
308
                #print(xplotname),
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
309
                plotOutput(plotname, height = 250))
310
      
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
311
    )
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
    local({ 
      
      output[[plotname]] <- renderPlot({
        print("hello itse mi")
        print(yplotname)
        
        data<- structure(list(V1=as.numeric(coconut.df[[input[[xplotname]]]]),
                              V2=as.numeric(coconut.df[[input[[yplotname]]]])),
                         .Names=c("V1","V2"), row.names=c(NA,10L), class = "data.frame")
        #print("data")
        #print(data)
        #Neues Plot
        barplot(data$V2,data$V1,
                ylab= yplotname,
                xlab=xplotname)
        
      })
    }) #Local end
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
330 331
  })
  
332 333
   
  #BARCHART view
334
  
335
  
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
  
  ## ALTES PLOT
  #a=1
  
  #for(a in 1:length(coconut.df$bluetooth.numOfBTDevices)){
  
  #g <-geom_bar(mapping = NULL, data = , stat = "count",
  #             position = "stack", width = NULL, binwidth = NULL, na.rm = FALSE,
  #             show.legend = NA, inherit.aes = TRUE)
  
  #g <- ggplot(coconut.df, aes("timestamp","bluetooth"))
  #g + geom_bar()
  # a=a+1}
  
  #g
  #hist(bluetooth)
  
353 354 355 356
  #BARCHART text
  output$bar_explain <- renderText({
    "Select data for the x- and y-axis then go to add barchart if you want this data to be visualized in a barchart."
  })
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
357
  
358 359
  
  
360
  #TIMELINE insert box
361 362
  output$time_box <- renderUI({
    if(input$check_time)
363 364
      box(  width = 12,
            title="Timeline",
365 366 367
            status= "warning",
            solidHeader = TRUE,
            collapsible = TRUE,
368
            timevisOutput("time", height = 175)
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
369
      )
370 371
  })
  
372
  #TIMELINE view
373
  output$time <- renderTimevis({
374
    print("TIME wird aufgerufen")
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
375
    
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
    print("Length:")
    print(length(parsedEndtimes))
    print("combined")
    print( c(anytime(totalST), head(parsedEndtimes, -1)))
    print("endtimes")
    print(parsedEndtimes)
    
    
    data <-  data.frame(
      id      = 1:length(parsedEndtimes),
      content= c(1:length(parsedEndtimes)),
      start   = c(anytime(totalST), head(parsedEndtimes, -1)),
      end     = parsedEndtimes
    )
    timevis(data)
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
391
    
392
  })
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
393
  
394
  #TIMELINE text
395
  output$texttimeline <- renderText({
396
    "Add Timeline for getting a Timeline about CoCoQuest Tasks and Questions.To see how long a the participant took for a certain task."
397
  })
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
398 399
  
  
400
  #LINECHART insert box
401 402
  output$line_box <- renderUI({
    if(input$check_line)
403 404
      box(  width = 12,
            title="Linechart",
405 406 407
            status= "warning",
            solidHeader = TRUE,
            collapsible = TRUE,
408
            
409
            #add_tooltip(data_tooltip, "hover"),
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
410
            line_plot<<-plotOutput("line", height = 250))
411 412
  })
  
413
  #LINECHART view
414 415
  output$line <- renderPlot({
    print("LINE wird aufgerufen")
416 417 418
    data<- structure(list(V1=as.numeric(coconut.df[[input$line_x]]), 
                          V2=as.numeric(coconut.df[[input$line_y]])),
                     .Names=c("V1","V2"), row.names=c(NA,6L), class = "data.frame")
419
    print(data)
420
    plot(data$V1,data$V2, type="l", ylab=input$line_y, xlab=input$line_x)
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
421
    
422 423
  })
  
424 425 426 427 428 429 430
  #LINECHART text
  output$line_explain <- renderText({
    "Select data for the x- and y-axis then go to add linechart if you want this data to be visualized in a linechart."
  })
  
  
  #SCATTERPLOT insert box
431 432
  output$scat_box <- renderUI({
    if(input$check_scat)
433 434
      box(  width = 12,
            title="Scatterplot",
435 436 437
            status= "warning",
            solidHeader = TRUE,
            collapsible = TRUE,
438
           
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
439
           scat_plot<<- plotOutput("scat", height = 250))
440 441
  })
  
442
  #SCATTERPLOT view
443
  output$scat <- renderPlot({
444 445
    data<- structure(list(V1=as.numeric(coconut.df[[input$scat_x]]), 
                          V2=as.numeric(coconut.df[[input$scat_y]])),
446 447 448
                     .Names=c("V1","V2"), row.names=c(NA,6L), class = "data.frame")
    print("SCAT wird aufgerufen")
    
449
    plot(data$V1,data$V2, type="p", xlab=input$scat_x, ylab=input$scat_y )
450 451
  })
  
452 453 454 455 456 457
  #SCATTERPLOT text
  output$scat_explain <- renderText({
    "Select data for the x- and y-axis then go to add scatterplot if you want this data to be visualized in a scatterplot."
  })
  
  #BOXPLOT insert box
458 459
  output$box_box <- renderUI({
    if(input$check_box)
460 461
      box(  width = 12,
            title="Boxplot",
462 463 464
            status= "warning",
            solidHeader = TRUE,
            collapsible = TRUE,
465
            
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
466
           box_plot<<- plotOutput("box", height = 250))
467 468
  })
  
469 470
  #BOXPLOT view
  #TODO:scaling 
471 472
  output$box <- renderPlot({
    print("BOX wird aufgerufen")
Stephanie Wegscheidl's avatar
boxplot  
Stephanie Wegscheidl committed
473 474 475
    data<- structure(list(V1=as.numeric(coconut.df[[input$box_x]])),
                     .Names=c("V1"), row.names=c(NA,6L), class = "data.frame")
    
476
    boxplot(data$V1, type="box", xlab=input$box_x )
477 478
  })
  
479 480 481 482 483 484
  #BOXPLOT text
  output$box_explain <- renderText({
    "Select data then go to add boxplot if you want this data to be visualized in a boxplot."
  })
  
  #MAP insert box
485 486
  output$map_box <- renderUI({
    if(input$check_map)
487 488
      box(  width = 12,
            title="Map",
489 490 491
            status= "warning",
            solidHeader = TRUE,
            collapsible = TRUE,
492
           
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
493
            map_plot<<-leafletOutput("map", height = 250))
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
494 495
  })
  
496
  #MAP view 
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
497
  output$map <- renderLeaflet({
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
    print("MAP wird aufgerufen")
    data <- as.numeric(coconut.df[[input$map_data]])
    max_data<<- max(data)
    c<-1
    for(c in 1:length(data)){
      data[c]<-(data[c]/max_data)*10
    }
    
    colorData <-
      cut(
        data,
        c(0, 2, 5, 7, 10),
        include.lowest = T,
        lables = c('<2', '<5', '<7', '<10')
      )
    
    colorGrad <- colorFactor('RdYlGn', colorData) 
    
516
    m <<- leaflet()
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
517
    x=1
518 519 520
    m <<- addTiles(m)
    m<<-addCircleMarkers(m,lng=as.numeric(coconut.df$gps.longitude), lat=as.numeric(coconut.df$gps.latitude), radius = data, color = colorGrad(colorData)) #addPolylines does not work
    m<<-addLegend(m, 'bottomright', pal=colorGrad, values=colorData, title=' ',opacity=1)
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
521
    m
522 523
  })
  
524 525 526 527
  #MAP text
  output$map_explain <- renderText({
    paste("Select data then go to add map. The map will show the way the participant went, also the data you selected is going to be normalized (highest value=10).")
  })
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
528
  
529
  #TODO: TOOLTIP
530 531 532 533 534
  data_tooltip <- function(x){
    if(is.null(x)) return(NULL)
    if(is.null(x$ID)) return(NULL)
    paste0(coconut.df[[input$line_x]])
  }
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
535
  
536
  #TODO: DownloadButton
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
  plotinput <- function() {
    #df<-data.frame(q=c(1,3,5,7,9),w=c(2,4,6,8,10),z=c(1,2,3,4,5))
    list(p1 = map_plot,
         p2 = line_plot,
         p3 = scat_plot)
  }
  
  output$down.pdf <- downloadHandler(
    ##FIRST TRY
    # print("download wird aufgerufen"),
    # filename = function() { paste('plot', '.png', sep='') },
    # content = function() {
      # ggsave(plot=map_plot, file=input$nut$datapath)
    #}
  
    #SECOND TRY
553 554
    print("breakoint"),
    filename = function(){paste("Graphs",'.pdf', sep='')},
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
555
    content = function(file) {
556
      cairo_pdf(filename = file, width=12, height=8)
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
557
      #boxplot(data$V1, type="box", xlab=input$box_x)
558 559
      #m
      #leafletOutput("map", height = 250)
560
      plot(data$V1,data$V2, type="p", xlab=input$scat_x, ylab=input$scat_y )     
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
      dev.off()
    })
  
  ##THIRD TRY
  # observeEvent(input$down.pdf, {
  #   
  #     pdf("www/myreport.pdf")
  #     plotinput()
  #     dev.off()
  #     tags$iframe(style="height:600px; width:100%", src="myreport.pdf")
  #   
  # })
  
  
  
  
577 578 579 580 581 582 583 584 585 586 587
  

  
  
  
  
  
  
  ################## SOME STUFF ################
  
  ##DOWNLOADBUTTON
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
588
  #observeEvent(input$screenshot,{
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
  #if(input$check_line|input$check_time|input$check_map|input$check_hist)
  #disable("screenshot")
  #webshot::install_phantomjs()
  
  # cdat <<- session$clientData
  # url <- paste0(cdat$url_hostname,":", cdat$url_port,"/")
  # print(url)
  
  #URL <- "http://rstudio.github.io/leaflet/"
  #appshot("cocoVisR/", file = "dashboard.png", port = getOption("shiny.port"), envvars = NULL)
  #webshot(url,delay = 5.0)
  #knit("dashboard.png")
  #port <- cdat$url_port
  #mapshot(m, file="~/Rplot.png")
  
  #webshot(url, "dashboard.png", delay = 20.0) # does NOT WORK 
  #appdir <- system.file("examples", "01_hello", package="shiny")
  #print("appdir")
  #print(appdir)
  #appshot(appdir, "01_hello.png")
  
  #leaflet.print(m)
  
  
  
  
  
  
  
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
618
  #})
619
  # url <- paste0(cdat$url_protocol,"//",cdat$url_hostname,":", cdat$url_port, cdat$url_pathname,cdat$url_search)
620
  #output$downButton <- downloadHandler(
Stephanie Wegscheidl's avatar
Stephanie Wegscheidl committed
621 622 623 624 625 626 627
  # filename="dashboard.png",
  #content=function(file){
  # observeEvent(input$downButton, {
  #appshot("cocoVisR/dashboard", file = "dashboard.png", port = getOption("shiny.port"), envvars = NULL)
  
  #}) 
  #}
628
  #)
629 630 631
  
  
  
632
  ##BARCHART
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
  #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
650
}