-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrenderpreddata.R
More file actions
137 lines (125 loc) · 5.74 KB
/
renderpreddata.R
File metadata and controls
137 lines (125 loc) · 5.74 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
renderpreddata = function(data,
feat_props,
current_page,
init_ID_format,
output) {
data = data.frame(data)
sig_digies = c()
col_names = colnames(data)
for (i in 2:(ncol(data)-4)) {
if (colnames(data)[i] %in% keys(feat_props)) {
sig_digies = append(sig_digies, values(feat_props, keys = col_names[i])[[1]])
} else {
sig_digies = append(sig_digies, 3)
}
}
PL = 5000
sig_digies1 = c(sig_digies,3,3,3)
if (init_ID_format == "YMD") {
data[,1] = ymd(data[,1])
date_format_string = "toLocaleDateString"
} else if (init_ID_format == "MDY") {
data[,1] = mdy(data[,1])
date_format_string = "toLocaleDateString"
} else if (init_ID_format == "MDYHM") {
data[,1] = parse_date_time(data[,1],c('%m/%d/%y %H:%M'),exact=TRUE)
date_format_string = "toLocaleString"
} else if (init_ID_format == "Character") {
date_format_string = "Character"
} else if (init_ID_format == "Numeric") {
date_format_string = "Numeric"
}
if (date_format_string != "Numeric" && date_format_string != "Character") {
output$pd_data = DT::renderDT(server = T, {
datatable(
data,
rownames = F,
extensions = 'Buttons',
selection = "none",
editable = list(target = "cell", disable = list(columns = c((ncol(data)-3):ncol(data)))),
options = list(
autoWidth = F,
dom='ltBp',
paging = FALSE,
pageLength = PL,
displayStart = current_page * PL - PL,
scrollX = TRUE,
scrollY = TRUE,
buttons = c('copy', 'csv', 'excel'),
columnDefs = list(
list(targets = 0, className = 'dt-center', type = 'string'),
list(targets = '_all', className = 'dt-center',createdCell = JS("function(td, cellData, rowData, row, col) {","$(td).css({'min-width': '75px'});","}"))),
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#073744', 'color': '#fff'});",
"Shiny.setInputValue('tableRendered', 'pd_data', {priority: 'event'});","}"))) |>
formatStyle(columns = 1:2, backgroundColor = "#b0bed9") |>
formatStyle(columns = 3:(ncol(data)-4),color = styleEqual(-999, "white", default = "black"),
backgroundColor = styleEqual(-999, "#BA0C2F", default = "#aaeeaa")) |>
formatStyle(columns = (ncol(data)-3):ncol(data), backgroundColor = "lightgray") |>
formatRound(columns = 2:(ncol(data)-1),digits = sig_digies1) %>%
formatDate(columns=1, date_format_string)
})
} else if (date_format_string == "Numeric") {
sig_digies2 = c(3,sig_digies1)
output$pd_data = DT::renderDT(server = T, {
datatable(
data,
rownames = F,
extensions = 'Buttons',
selection = "none",
editable = list(target = "cell", disable = list(columns = c((ncol(data)-3):ncol(data)))),
options = list(
autoWidth = F,
dom='ltBp',
paging = FALSE,
pageLength = PL,
displayStart = current_page * PL - PL,
scrollX = TRUE,
scrollY = TRUE,
buttons = c('copy', 'csv', 'excel'),
columnDefs = list(
list(targets = 0, className = 'dt-center', type = 'string'),
list(targets = '_all', className = 'dt-center',createdCell = JS("function(td, cellData, rowData, row, col) {","$(td).css({'min-width': '75px'});","}"))),
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#073744', 'color': '#fff'});",
"Shiny.setInputValue('tableRendered', 'pd_data', {priority: 'event'});","}"))) |>
formatStyle(columns = 1:2, backgroundColor = "#b0bed9") |>
formatStyle(columns = 3:(ncol(data)-4),color = styleEqual(-999, "white", default = "black"),
backgroundColor = styleEqual(-999, "#BA0C2F", default = "#aaeeaa")) |>
formatStyle(columns = (ncol(data)-3):ncol(data), backgroundColor = "lightgray") |>
formatRound(columns = 1:(ncol(data)-1),digits = sig_digies2)
})
} else if (date_format_string == "Character") {
output$pd_data = DT::renderDT(server = T, {
datatable(
data,
rownames = F,
extensions = 'Buttons',
selection = "none",
editable = list(target = "cell", disable = list(columns = c((ncol(data)-3):ncol(data)))),
options = list(
autoWidth = F,
dom='ltBp',
paging = FALSE,
pageLength = PL,
displayStart = current_page * PL - PL,
scrollX = TRUE,
scrollY = TRUE,
buttons = c('copy', 'csv', 'excel'),
columnDefs = list(
list(targets = 0, className = 'dt-center', type = 'string'),
list(targets = '_all', className = 'dt-center',createdCell = JS("function(td, cellData, rowData, row, col) {","$(td).css({'min-width': '75px'});","}"))),
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#073744', 'color': '#fff'});",
"Shiny.setInputValue('tableRendered', 'pd_data', {priority: 'event'});","}"))) |>
formatStyle(columns = 1:2, backgroundColor = "#b0bed9") |>
formatStyle(columns = 3:(ncol(data)-4),color = styleEqual(-999, "white", default = "black"),
backgroundColor = styleEqual(-999, "#BA0C2F", default = "#aaeeaa")) |>
formatStyle(columns = (ncol(data)-3):ncol(data), backgroundColor = "lightgray") |>
formatRound(columns = 2:(ncol(data)-1),digits = sig_digies1)
})
}
}