use_font: Use a downloaded font in Shiny or Markdown

Description Usage Arguments Value Examples

View source: R/use_font.R

Description

Use a downloaded font in Shiny or Markdown

Usage

1
use_font(id, css_path, selector = "body", css = NULL)

Arguments

id

Id of the font downloaded.

css_path

Path to CSS generated by setup_font.

selector

CSS selector for which to use the font, usually an HTML tag, default to "body" (all document).

css

CSS variables needed to use font, normally this should be automatic.

Value

an HTML tag with an HTML dependency (htmlDependency).

Examples

 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
if (interactive()) {
  library(gfonts)

  # Here we use a temp directory
  # but in Shiny, it can be www/ folder
  directory <- tempfile()
  dir.create(directory)

  # Setup a font (only needed once)
  setup_font(
    id = "dancing-script",
    output_dir = directory
  )

  library(shiny)

  ui <- fluidPage(

    # Use font
    use_font(
      id = "dancing-script",
      css_path = file.path(directory, "css/dancing-script.css")
    ),

    tags$p(
      paste(letters, collapse = "")
    ),
    tags$p(
      paste(LETTERS, collapse = "")
    ),
    tags$p(
      style = "font-weight: bold;",
      paste(letters, collapse = "")
    ),
    tags$p(
      style = "font-weight: bold;",
      paste(LETTERS, collapse = "")
    ),
    tags$p(
      style = "font-style: italic;",
      paste(letters, collapse = "")
    ),
    tags$p(
      style = "font-style: italic;",
      paste(LETTERS, collapse = "")
    ),
    tags$h1("First level title"),
    tags$h2("Second level title"),
    tags$h3("Third level title"),
    tags$h4("Fourth level title"),
    tags$h5("Fifth level title"),
    tags$h6("Sixth level title")
  )

  server <- function(input, output, session) {

  }
  shinyApp(ui, server)
}

gfonts documentation built on Jan. 13, 2021, 4:35 a.m.