-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdashboardPage.R
130 lines (124 loc) · 3.9 KB
/
dashboardPage.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
#' Create a Boostrap 4 dashboard page
#'
#' Build a tabler dashboard page
#'
#' @param navbar Slot for \link{tablerDashNav}.
#' @param body Slot for \link{tablerDashBody}.
#' @param footer Slot for \link{tablerDashFooter}.
#' @param title App title.
#' @param enable_preloader Whether to enable a page loader. FALSE by default.
#' @param loading_duration Loader duration in seconds. 2s by default.
#'
#' @examples
#' if(interactive()){
#' library(shiny)
#' library(tablerDash)
#'
#' shiny::shinyApp(
#' ui = tablerDashPage(
#' navbar = tablerDashNav(),
#' footer = tablerDashFooter(),
#' title = "test",
#' body = tablerDashBody()
#' ),
#' server = function(input, output) {}
#' )
#' }
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
tablerDashPage <- function(navbar = NULL, body = NULL,
footer = NULL, title = NULL,
enable_preloader = FALSE,
loading_duration = 2){
# hide body and footer
bodyContent <- shiny::tags$div(
class = "page-main",
style = if (enable_preloader) "visibility: hidden;" else NULL,
navbar,
body
)
footer <- shiny::tagAppendAttributes(footer, class = "footer")
footer <- if (enable_preloader) {
shiny::tagAppendAttributes(footer, style = "visibility: hidden;")
}
# preloader
preloader <- shiny::tags$div(
class = "dimmer active",
shiny::tags$div(
class = "loader",
style = "
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: visible;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;",
shiny::tags$div(
class = "dimmer-content"
)
)
)
shiny::tags$html(
# Head
shiny::tags$head(
shiny::tags$meta(charset="UTF-8"),
shiny::tags$meta(
name = "viewport",
content = "
width=device-width,
user-scalable=no,
initial-scale=1.0,
maximum-scale=1.0,
minimum-scale=1.0"
),
shiny::tags$meta(`http-equiv` = "X-UA-Compatible", content = "ie=edge"),
shiny::tags$meta(`http-equiv` = "Content-Language", content = "en"),
shiny::tags$meta(name = "msapplication-TileColor", content = "#2d89ef"),
shiny::tags$meta(name = "theme-color", content = "#4188c9"),
shiny::tags$meta(name = "apple-mobile-web-app-status-bar-style", content = "black-translucent"),
shiny::tags$meta(name = "apple-mobile-web-app-capable", content = "yes"),
shiny::tags$meta(name = "mobile-web-app-capable", content = "yes"),
shiny::tags$meta(name = "HandheldFriendly", content = "True"),
shiny::tags$meta(name = "MobileOptimized", content = "320"),
#<link rel="icon" href="./favicon.ico" type="image/x-icon">
#<link rel="shortcut icon" type="image/x-icon" href="./favicon.ico">
shiny::includeCSS(path = "https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300i,400,400i,500,500i,600,600i,700,700i&subset=latin-ext"),
shiny::tags$title(title)
),
# Body
addDeps(
shiny::tags$body(
class = NA,
# set up a time-out for the preloader
# The body content disappears first,
# then 2s after, the preloader disappears and
# the body content is shown
onload = if (enable_preloader) {
duration <- loading_duration * 1000
paste0(
"$(document).ready(function() {
setTimeout(function(){
$('.dimmer.active').remove();
$('.page-main').css('visibility', 'visible');
$('.footer').css('visibility', 'visible');
}, ", duration, ");
});
"
)
},
shiny::tags$div(
class = "page",
if (enable_preloader) preloader,
bodyContent,
footer
)
)
)
)
}