-
Notifications
You must be signed in to change notification settings - Fork 2
/
tabs.R
156 lines (146 loc) · 3.8 KB
/
tabs.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
#' Create an advanced tabset
#'
#' Advanced tabset panel with styles and features
#'
#' @param ... Content of the tabset, created using the tabPanel for each individual item
#' @param type Type of tabset to create, choices include "default","pills","clean","jPills","justified"
#' @param border Include a board for the tabset, TRUE or FALSE
#' @param justified Justify tab headers, TRUE or FALSE
#' @param position position of the tabs, choices include "left","end","center"
#'
#' @note Many examples exist for the tabset, fid them using the package load.example function
#'
#' @return An HTML containing elements of a tabset to be embedded in a page
#'
#' @examples
#' \donttest{
#' if (interactive()) {
#' library(shiny)
#' library(nextGenShinyApps)
#' tab2 <- tabPanel("Summary", "SAMPLE nunc.")
#' tab3 <- tabPanel("Tab 3", "aoreet sit amet.")
#' tab4 <- tabPanel("Tab 4", "Vulputate pulvinar")
#'
#'
#' shiny::shinyApp(
#' ui = fluidPage(
#' style = "8",
#' custom.bg.color = "rgb(110,134,032)",
#' sidebar = NULL,
#' header = NULL,
#' tabsetPanel(
#' tab2,
#' tab3,
#' type = "pills",
#' justified = TRUE
#' )
#' ),
#' server = function(input, output) {
#' }
#' )
#' }
#' }
#'
#' @export
#'
#'
tabsetPanel <- function(..., type = c("default", "pills", "clean", "jPills", "justified"), border = TRUE, justified = FALSE, position = c("left", "end", "center")) {
# get the type of tabset
type <- match.arg(type)
# insert class based on the tabset
type.class <- switch(type,
"default" = {
" nav-tabs"
},
"pills" = {
" nav-pills"
},
"clean" = {
" nav-tabs nav-tabs-clean"
},
"jPills" = {
" nav-pills nav-justified"
},
"justified" = {
" nav-tabs nav-fill"
}
)
justified.class <- switch(justified,
" nav-justified",
""
)
if (justified) position <- "none"
tabItems <- list(...)
count.pre <- as.integer(Sys.time()) - rand.num(1)
count.title <- 0
part.title <- ""
part.content <- ""
for (tab in tabItems) {
count.title <- count.title + 1
activeOrNot <- ifelse(count.title == 1, " active", "")
# for title
part.title <- paste0(part.title, tags$li(
class = "nav-item",
tags$a(
class = paste0("nav-link", activeOrNot), `data-toggle` = "tab", href = paste0("#tab_justified-", count.pre, count.title), role = "tab",
tab$title
)
))
# for content
part.content <- paste0(part.content, div(
class = paste0("tab-pane fade show", activeOrNot), id = paste0("tab_justified-", count.pre, count.title), role = "tabpanel",
tab$content
))
}
if (border) {
div(
class = "panel",
div(
class = "panel-container show",
div(
class = "panel-content",
tags$ul(
class = paste0("nav", type.class, " justify-content-", position, justified.class), role = "tablist",
HTML(part.title)
),
div(
class = "tab-content p-3",
HTML(part.content)
)
)
)
)
} else {
div(
tags$ul(
class = paste0("nav", type.class, " justify-content-", position, justified.class), role = "tablist",
HTML(part.title)
),
div(
class = "tab-content p-3",
HTML(part.content)
)
)
}
}
#' Create a tab panel item
#'
#' Create a tab panel item that is enclosed by a tabsetPanel
#'
#' @param title title of the tab
#' @param ... content of the tab
#'
#' @return An list containing the title and content of a tab
#'
#' @examples
#' if (interactive()) {
#' tabPanel("Summary", "Convallis aesus.")
#' tabPanel("Summary", "nextGenShinyAppss.")
#' }
#'
#' @export
#'
#'
tabPanel <- function(title, ...) {
list(title = title, content = htmltools::div(...))
}