This repository has been archived by the owner on Dec 30, 2023. It is now read-only.
forked from nicebread/p-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpancollapse.R
87 lines (72 loc) · 2.46 KB
/
pancollapse.R
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
library(shiny)
library(xtable)
library(htmltools)
library(utils)
pancollapse <- function(){
tags$head(tags$link(rel="stylesheet", type="text/css", href="pancollapse.css"),
tags$script(src="pancollapse.js"))
}
alert.create <- function(content, style="info") {
HTML(paste0('<div class="alert alert-', style, ' alert-dismissible" role="alert">'),
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>',
content,
'</div>'
)
}
pancollapse.create <- function(title, content, class="panel-default"){
HTML('<div class="panel ', class, '"><div class="panel-heading panel-heading-collapse"><h4 class="panel-title">',
title,
'<span class="pull-right"><i class="glyphicon glyphicon-chevron-up"></i></span></h4></div><div class="panel-body panel-collapse collapse">',
content,
'</div></div>'
)
}
panel.create <- function(title, content) {
HTML('<div class="panel panel-default"><div class="panel-heading"><h4 class="panel-title">',
title,
'</h4></div><div class="panel-body">',
content,
'</div></div>'
)
}
getTable <- function(df, cbGetClass = NULL) {
thead <- paste0('<th>', htmlEscape(names(df)), '</th>', collapse='')
tbody <- rep("",nrow(df))
for(row in 1:nrow(df)) {
format <- '<td>%s</td>'
tbody[row] <- paste0(sapply(df[row,], function(x){ sprintf('<td>%s</td>', htmlEscape(as.character(x))) }), collapse='');
cls <- NULL
if( is.function(cbGetClass) ) {
cls <- cbGetClass(df[row,])
}
if(is.character(cls)) {
tbody[row] <- sprintf('<tr class="%s">%s</tr>', htmlEscape(cls), tbody[row])
} else {
tbody[row] <- sprintf('<tr>%s</tr>', tbody[row])
}
}
tbody2 <- paste0(tbody, collapse='')
HTML(
'<div class="table-responsive"><table style="font-size:80%;" class="data table table-condensed"><thead><tr>',
thead,
'</tr></thead><tbody>',
tbody2,
'</tbody></table></div>'
)
}
classWhenValueFun <- function(col.name, value, cls) {
return(function(named.row){
tmp <- named.row[[col.name]]
if(!is.null(tmp) && !is.na(tmp) && tmp == value) cls
})
}
readFile <- function(filename) {
fileConnection <- file(filename, encoding="UTF-8")
text <- readChar(fileConnection, file.info(filename)$size, useBytes = TRUE)
Encoding(text) <- "UTF-8"
close(fileConnection)
text
}
loadHTML <- function(filename) {
HTML(readFile(filename))
}