comparison aurora_data.Rmd @ 0:ebb7afcb2b75 draft default tip

planemo upload
author mingchen0919
date Tue, 17 Apr 2018 10:58:55 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ebb7afcb2b75
1 ---
2 title: 'HTML report title'
3 output:
4 html_document:
5 highlight: pygments
6 ---
7
8 ```{r, echo=FALSE}
9 # to make the css theme to work, <link></link> tags cannot be added directly
10 # as <script></script> tags as below.
11 # it has to be added using a code chunk with the htmltool functions!!!
12 css_link = tags$link()
13 css_link$attribs = list(rel="stylesheet", href="vakata-jstree-3.3.5/dist/themes/default/style.min.css")
14 css_link
15 ```
16
17 ```{r, eval=FALSE, echo=FALSE}
18 # this code chunk is purely for adding comments
19 # below is to add jQuery and jstree javascripts
20 ```
21 <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
22 <script src="vakata-jstree-3.3.5/dist/jstree.min.js"></script>
23
24 ```{r, eval=FALSE, echo=FALSE}
25 # this code chunk is purely for adding comments
26 # javascript code below is to build the file tree interface
27 # see this for how to implement opening hyperlink: https://stackoverflow.com/questions/18611317/how-to-get-i-get-leaf-nodes-in-jstree-to-open-their-hyperlink-when-clicked-when
28 ```
29 <script>
30 $(function () {
31 // create an instance when the DOM is ready
32 $('#jstree').jstree().bind("select_node.jstree", function (e, data) {
33 window.open( data.node.a_attr.href, data.node.a_attr.target )
34 });
35 });
36 </script>
37
38 ```{r setup, include=FALSE, warning=FALSE, message=FALSE}
39 knitr::opts_chunk$set(echo = TRUE, error = TRUE)
40 ```
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 # Output
63
64 ```{bash, echo=FALSE}
65 # copy jstree directory to output directory
66 cp -r ${X_t}/vakata-jstree-3.3.5 ${X_d}
67 ```
68
69 ```{r, echo=FALSE}
70 # get the OUTPUT_DIR folder data: dataset_NUMBER_files
71 output_dir = tail(strsplit(opt$X_d, '/')[[1]], 1)
72 # define a recursive function to build html string of the file tree
73 file_tree = function(dir = '.'){
74 files = list.files(path = dir, recursive = FALSE, full.names = TRUE)
75 # files also include directorys, need to remove directorys
76 files = files[!dir.exists(files)]
77 dirs = list.dirs(path = dir, recursive = FALSE, full.names = TRUE)
78 tags$ul(
79 {
80 if (length(files) > 0) {
81 lapply(files, function(x){
82 path_end = tail(strsplit(x, '/')[[1]],1)
83 href_path = strsplit(x, paste0(output_dir, '/'))[[1]][2]
84 li_item = tags$li(tags$a(path_end, href=href_path))
85 li_item$attribs = list('data-jstree'='{"icon":"jstree-file"}')
86 li_item
87 })
88 }
89 },
90 {
91 if (length(dirs) > 0) {
92 lapply(dirs, function(x){
93 x_path = strsplit(x, paste0(output_dir, '/'))[[1]][2]
94 li_item = tags$li(x_path, file_tree(x))
95 li_item$attribs = list('data-jstree'='{"icon":"jstree-folder"}')
96 li_item
97 })
98 }
99 }
100 )
101 }
102 ```
103
104 ```{r, echo=FALSE}
105 # create a div container to store the file tree interface
106 tags$div(
107 id="jstree",
108 file_tree(opt$X_d)
109 )
110 ```
111