1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
### Author: Franck Soubès
### Bioinformatics Master Degree - University of Bordeaux, France
### Link: https://github.com/GeT-TRiX/MA_Trix_App/
### Where: GET-TRiX's facility
### Application: MATRiX is a shiny application for Mining and functional Analysis of TRanscriptomics data
### Licence: GPL-3.0

#########################################
######## From Shiny to highcharts       #
#########################################



#' addpercentpop is a reactive function that divide the count (list of genes) by the Pop.hits in the resulting david dataframe
#'
#' @param myresdavitab An outputed reactive dataframe (DAVID)

#' @return A reactive dataframe with computed hits 
#'
#' @export


addpercentpop <- reactive({

  req(myresdavitab())
  reumdiff = lapply(1:length(myresdavitab()),function(x)return(sapply(length(myresdavitab()[[x]]$Count), function(y){
    return(as.numeric(as.character(myresdavitab()[[x]]$Count))/as.numeric(as.character(myresdavitab()[[x]]$Pop.Hits))*100)})) %>%
      mutate(myresdavitab()[[x]],percent = .)) %>% bind_rows()
})

#' dfenrichtojson is a reactive function that convert dataframe R object to json
#'
#' @param addpercentpop A reactive dataframe
#' @param enrichbased A reactive character value to filter the top n terms based on the pvalue or the fold enrichment
#'
#' @return A json objejct
#'
#' @export


dfenrichtojson <- reactive({

  req(addpercentpop())
  filtered <- addpercentpop()
  return(DftoHighjson(filtered, input$enrichbased))

})


observe({ # Display highchart bubble
  req(dfenrichtojson(), input$enrichbased )

  axisParameters <- list(
    topcatdav = list( min = 0, max = 12, legend = 'Source: <a href="https://www.highcharts.com/"  target="_blank">Plot produce with highcharts</a> and <a href="https://shiny.rstudio.com/" target= "_blank">Shiny</a>',
                      title= "top genes", xaxis = ifelse(input$enrichbased == "FoldE", "Fold Enrichment", "pvalue"))
  )

  newData <- c(axisParameters$topcatdav, list(series=dfenrichtojson()))
  islab = input$addlabelhigh
  session$sendCustomMessage(type="updateVariable", newData) # send to javascript data
  session$sendCustomMessage("handler1", islab) #send to javascript labels
})