Skip to content

Commit c794b97

Browse files
committed
updating chapther 04
1 parent 12df53d commit c794b97

15 files changed

+316
-124
lines changed

04_handle-html-dependencies-with-htmltools.Rmd

Lines changed: 174 additions & 123 deletions
Large diffs are not rendered by default.

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ Imports:
1818
purrr,
1919
rmarkdown,
2020
shiny,
21-
shinydashboard
21+
shinydashboard,
22+
shinydashboardPlus
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
library(shiny)
3+
4+
my_card <- function(...) {
5+
withTags(
6+
div(
7+
class = "card",
8+
div(
9+
class = "card-body",
10+
h5(class = "card-title", "Card title"),
11+
p(class = "card-text", "Card content"),
12+
button(
13+
type = "button",
14+
class = "btn btn-primary",
15+
"Button"
16+
)
17+
)
18+
)
19+
)
20+
}
21+
22+
shinyApp(
23+
ui = fluidPage(
24+
fluidRow(
25+
column(
26+
width = 6,
27+
align = "center",
28+
br(),
29+
my_card("Card Content")
30+
)
31+
)
32+
),
33+
server = function(input, output) {}
34+
)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
library(shiny)
3+
4+
my_card <- function(...) {
5+
withTags(
6+
div(
7+
class = "card",
8+
div(
9+
class = "card-body",
10+
h5(class = "card-title", "Card title"),
11+
p(class = "card-text", "Card content"),
12+
button(
13+
type = "button",
14+
class = "btn btn-primary",
15+
"Button"
16+
)
17+
)
18+
)
19+
)
20+
}
21+
22+
mdb_cdn <- "https://cdnjs.cloudflare.com/ajax/libs/"
23+
mdb_css <- paste0(mdb_cdn, "mdb-ui-kit/3.6.0/mdb.min.css")
24+
25+
26+
shinyApp(
27+
ui = fluidPage(
28+
tags$style("body {background: gainsboro;}"),
29+
30+
## load the css code
31+
tags$head(
32+
## Adding a link
33+
tags$link(
34+
rel = "stylesheet",
35+
type = "text/css",
36+
href = mdb_css
37+
),
38+
## Pasting all css code
39+
#includeCSS(path = mdb_css)
40+
),
41+
fluidRow(
42+
column(
43+
width = 6,
44+
br(),
45+
my_card("Card Content")
46+
)
47+
)
48+
),
49+
server = function(input, output) {}
50+
)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
library(shiny)
3+
library(htmltools)
4+
5+
my_card <- function(...) {
6+
withTags(
7+
div(
8+
class = "card",
9+
div(
10+
class = "card-body",
11+
h5(class = "card-title", "Card title"),
12+
p(class = "card-text", "Card content"),
13+
button(
14+
type = "button",
15+
class = "btn btn-primary",
16+
"Button"
17+
)
18+
)
19+
)
20+
)
21+
}
22+
23+
# handle dependency
24+
mdb_cdn <- "https://cdnjs.cloudflare.com/ajax/libs/"
25+
mdb_card_dep <- function() {
26+
htmlDependency(
27+
name = "mdb-card",
28+
version = "1.0",
29+
src = c(href = mdb_cdn),
30+
stylesheet = "mdb-ui-kit/3.6.0/mdb.min.css"
31+
)
32+
}
33+
34+
# create the card
35+
my_card_with_deps <- function(...) {
36+
cardTag <- my_card(...)
37+
38+
tagList(cardTag, mdb_card_dep())
39+
40+
}
41+
42+
43+
shinyApp(
44+
ui = fluidPage(
45+
tags$style("body {background: gainsboro;}"),
46+
47+
fluidRow(
48+
column(
49+
width = 6,
50+
br(),
51+
my_card_with_deps("Card Content")
52+
)
53+
)
54+
),
55+
server = function(input, output) {}
56+
)
19.4 KB
Loading
4.59 KB
Loading
74.2 KB
Loading
95.3 KB
Loading
100 KB
Loading

0 commit comments

Comments
 (0)