-
Notifications
You must be signed in to change notification settings - Fork 0
/
uiHelper.R
159 lines (136 loc) · 3.3 KB
/
uiHelper.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#'
#' Contains some UI helper functions
#'
#' Creates a string "input['<input>'] == <equals>"
#'
#' @param input UI input name
#' @param equals Value to compare to. Note that you need to put strings into inverted commas
#'
conditionalPanel.equals <- function(input, equals) {
return(paste0("input['", input, "'] == ", equals))
}
#' Creates a header panel that is not collapsable
#' Meant for static grouping
#'
#' @param ...
#' @param header
#'
#' @return
#' @export
#'
#' @examples
headerPanel <- function( ... ,header = "") {
return(tags$div(class="panel panel-default header-panel",
tags$div(class="panel-heading", header),
tags$div(class="panel-body", ...)))
}
#' Creates an UI element that has text next to an icon
#'
#' @param icon A taglist containing the icon
#' @param text The text
#'
#' @return Shiny UI element
#' @export
#'
#' @examples
iconText <- function(icon, text) {
return(tags$span(icon, tags$span(text)))
}
#' Creates an UI element that has text next to an icon provided by icon() command
#'
#' @param faicon The name of the icon.
#' @param text The text
#' @param lib Icon provider
#'
#' @return Shiny UI element
#' @export
#'
#' @examples
faIconText <- function(faicon, text, lib = "font-awesome") {
return(iconText(icon(faicon, lib = lib), text))
}
#' Creates a horizontal divider UI element
#'
#' @return Shiny UI element
#' @export
#'
#' @examples
hDivider <- function() {
return(tags$div(class = "hdivider"))
}
#' Creates a vertical skip
#'
#' @return Shiny UI element
#' @export
#'
#' @examples
vSkip <- function(h = 5) {
return(tags$div(style = paste0("height: ", h, "px;")))
}
subSubBox <- function(...) {
return(tags$div(class = "sub-sub-box", ...))
}
#' Joins a vector to a string with a limit
#' Use this for UI
#'
#' @param x
#' @param sep
#' @param limit
#'
#' @return
#' @export
#'
#' @examples
strJoinLimited <- function(x, sep = ", ", limit = NULL) {
if(is.null(limit) || length(x) <= limit) {
return(paste(x, collapse = sep))
}
else {
return(paste0(paste(x[1:limit], collapse = sep), sep, "... (", length(x), ")"))
}
}
#' Creates a dropdown button for actionButtons
#'
#' @param id
#' @param label
#' @param content
#' @param icon
#' @param button.style
#'
#' @return
#' @export
#'
#' @examples
dropdownButton <- function(id, label, content, icon = NULL, button.style = "btn-default") {
wrapped <- lapply(content, function(x) { tags$li(x) })
return(tags$div(class = "dropdown dropdown-button",
tags$button(class = paste(c("btn", button.style, "dropdown-toggle"), collapse = " "),
type = "button",
"data-toggle" = "dropdown",
icon,
label,
tags$span(class = "caret")),
tags$ul(class = "dropdown-menu",
wrapped)))
}
#' Workaround for bug in shinyBS
#' Returns all collapse elements 2x (except if not) and then (as last entry) the current open one
#'
#' @param input
#' @param id
#'
#' @return
#' @export
#'
#' @examples
getOpenCollapseId <- function(input, id) {
l <- input[[id]]
t <- table(l)
c <- l[length(l)]
if(t[c] > 2 || t[c] == 1) {
return(c)
}
else {
return(NULL)
}
}