File size: 1,885 Bytes
c038271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73


#' render_genes_table
#'
#' @param all_pathways_tab a data table with a single column e.g.
#'  | gene_name |
#'    RPL22
#' @param selected a (1-based) vector of indices of selected genes
#' - used if we have been using pathways table and now we have switched back to
#'  genes tab and want to rerender the table, keeping the genes that we selected
#'  previously
#'
#' @return rendered DT table 
#' @export
#'
#' @examples
render_genes_table <- function(gene_tab, selected = NULL) {
  print(selected)
  DT::renderDT({
   
    DT::datatable(
      gene_tab,
      escape = FALSE,
      selection = list(
        mode = "multiple",
        selected = selected,
        target = "row"
      ),
      options = list(
        pageLength = 15
      )
    )
  })
}


#' render_pathways_table
#'
#' @param all_pathways_tab a data table with a single column e.g.
#'  | pathway |
#'    Covid-19
#' @param selected a (1-based) vector of indices of selected pathways
#' - used if we have been using gene table and now we have switched back
#'  to pathways and want to rerender the table, keeping the pathways that
#'  we selected previously
#'
#' @return rendered DT table 
#' @export
#'
#' @examples
render_pathways_table <- function(all_pathways_tab, selected = NULL) {
  print(selected)
  DT::renderDT({
    tab <- DT::datatable(
      all_pathways_tab,
      escape = FALSE,
      selection = list(
        mode = "multiple",
        selected = selected,
        target = "row"
      ),
      callback = htmlwidgets::JS('
                                  table.on("mouseover", "td", function() {
                                  var index = table.cell(this).index();
                                  Shiny.setInputValue("table-hover_pathway_genes", index, {priority: "event"});
                                   })'),
      options = list(pageLength = 15)
    )

    return(tab)
  })
}