Title: | Offline 'Google' Fonts for 'Markdown' and 'Shiny' |
---|---|
Description: | Download 'Google' fonts and generate 'CSS' to use in 'rmarkdown' documents and 'shiny' applications. Some popular fonts are included and ready to use. |
Authors: | Victor Perrier [aut, cre], Fanny Meyer [aut], Mario Ranftl [ctb, cph] (google-webfonts-helper) |
Maintainer: | Victor Perrier <[email protected]> |
License: | GPL-3 |
Version: | 0.2.0 |
Built: | 2024-10-29 04:31:54 UTC |
Source: | https://github.com/dreamrs/gfonts |
Download font files
download_font(id, output_dir, variants = NULL, ..., http_options = list())
download_font(id, output_dir, variants = NULL, ..., http_options = list())
id |
Id of the font, correspond to column |
output_dir |
Output directory where to save font files. |
variants |
Variant(s) to download, default is to includes all available ones. |
... |
Additional parameters to API query. |
http_options |
Arguments passed to |
a character vector of the filepaths extracted to, invisibly.
if (interactive()) { # For example, we use a temporary directory path_to_dir <- tempfile() dir.create(path_to_dir) # Download Roboto font download_font( id = "roboto", output_dir = path_to_dir ) # Get only regular, italic and bold download_font( id = "roboto", output_dir = path_to_dir, variants = c("regular", "300italic", "700") ) # Clean up unlink(path_to_dir, recursive = TRUE) }
if (interactive()) { # For example, we use a temporary directory path_to_dir <- tempfile() dir.create(path_to_dir) # Download Roboto font download_font( id = "roboto", output_dir = path_to_dir ) # Get only regular, italic and bold download_font( id = "roboto", output_dir = path_to_dir, variants = c("regular", "300italic", "700") ) # Clean up unlink(path_to_dir, recursive = TRUE) }
Generate CSS to import fonts
generate_css( id, variants = NULL, subsets = NULL, output = NULL, font_dir = "../fonts/", prefer_local_source = TRUE, browser_support = c("best", "modern"), ... )
generate_css( id, variants = NULL, subsets = NULL, output = NULL, font_dir = "../fonts/", prefer_local_source = TRUE, browser_support = c("best", "modern"), ... )
id |
Id of the font, correspond to column |
variants |
Variant of font to use. |
subsets |
Subsets to use. |
output |
Specifies path to output file for CSS generated. |
font_dir |
Fonts directory relative to |
prefer_local_source |
Generate CSS font-face rules in which user installed fonts are
preferred. Use |
browser_support |
Browser to support, choose |
... |
Arguments passed to |
a character string with CSS code (invisibly).
if (interactive()) { # Generate CSS code to use Roboto font cat(generate_css("roboto", "regular")) }
if (interactive()) { # Generate CSS code to use Roboto font cat(generate_css("roboto", "regular")) }
Retrieve from API all fonts currently available.
Use the id
field in other functions to reference the font you want to use.
get_all_fonts(...)
get_all_fonts(...)
... |
Arguments passed to |
a data.frame
.
if (interactive()) { # Retrieve all fonts currently available all_fonts <- get_all_fonts() }
if (interactive()) { # Retrieve all fonts currently available all_fonts <- get_all_fonts() }
Get detailed information about a font
get_font_info(id, subsets = NULL, ...)
get_font_info(id, subsets = NULL, ...)
id |
Id of the font, correspond to column |
subsets |
Select charsets, for example |
... |
Arguments passed to |
a data.frame
.
if (interactive()) { # Info about Roboto roboto <- get_font_info("roboto") }
if (interactive()) { # Info about Roboto roboto <- get_font_info("roboto") }
Download Google fonts and generate CSS to use in rmarkdown documents and shiny applications. Some popular fonts are included and ready to use.
Use setup_font
to get a font inside your current project,
then in a {shiny} application or {rmarkdown} document, you can use
use_font
to import the font.
Some fonts are included in this package and can be used directly with use_pkg_gfont
.
Victor Perrier (@dreamRs_fr)
Id and version of fonts included and available through use_pkg_gfont
.
included_fonts
included_fonts
A data frame with 8 rows and 5 variables:
Id for the font.
Name of the font.
Category.
Version number.
Last modified date.
This function will download the specified font into a directory of your project and generate CSS code to use it in a Shiny application or RMarkdown document.
setup_font( id, output_dir, variants = NULL, subsets = NULL, prefer_local_source = TRUE, browser_support = c("best", "modern"), ... )
setup_font( id, output_dir, variants = NULL, subsets = NULL, prefer_local_source = TRUE, browser_support = c("best", "modern"), ... )
id |
Id of the font, correspond to column |
output_dir |
Output directory where to save font and CSS files. Must be a directory. |
variants |
Variant(s) to download, default is to includes all available ones. |
subsets |
Subsets to download. |
prefer_local_source |
Generate CSS font-face rules in which user installed fonts are
preferred. Use |
browser_support |
Browser to support, choose |
... |
Arguments passed to |
None.
Two directories will be created (if they do not exist)
in the output_dir
specified: fonts/ and css/.
if (interactive()) { # For example, we use a temporary directory path_to_www <- tempfile() dir.create(path_to_www) # In a Shiny app, you can use the www/ directory # in Markdown, use a subfolder of your Rmd directory setup_font( id = "open-sans-condensed", output_dir = path_to_www ) # Clean up unlink(path_to_www, recursive = TRUE) }
if (interactive()) { # For example, we use a temporary directory path_to_www <- tempfile() dir.create(path_to_www) # In a Shiny app, you can use the www/ directory # in Markdown, use a subfolder of your Rmd directory setup_font( id = "open-sans-condensed", output_dir = path_to_www ) # Clean up unlink(path_to_www, recursive = TRUE) }
Generate HTML tags used in examples
tag_example(class = NULL)
tag_example(class = NULL)
class |
Class of the main div. |
HTML tags.
tag_example()
tag_example()
Use a downloaded font in Shiny or Markdown
use_font(id, css_path, selector = "body", css = NULL)
use_font(id, css_path, selector = "body", css = NULL)
id |
Id of the font downloaded. |
css_path |
Path to CSS generated by |
selector |
CSS selector for which to use the font,
usually an HTML tag, default to |
css |
CSS variables needed to use font, normally this should be automatic. |
an HTML tag with an HTML dependency (htmlDependency
).
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) }
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) }
For convenience, some fonts are included in the package, you can use them without having to download them, but only few variants are available.
use_pkg_gfont( font = c("roboto", "open-sans", "lato", "montserrat", "alegreya", "nunito-sans", "baloo", "happy-monkey", "henny-penny", "poppins", "oswald"), selector = "body" )
use_pkg_gfont( font = c("roboto", "open-sans", "lato", "montserrat", "alegreya", "nunito-sans", "baloo", "happy-monkey", "henny-penny", "poppins", "oswald"), selector = "body" )
font |
Name of the font to use, possible choices are: |
selector |
CSS selector for which to use the font,
usually an HTML tag, default to |
An HTML tag with an htmlDependency
.
if (interactive()) { library(gfonts) library(htmltools) browsable(tags$div( use_pkg_gfont("open-sans"), tag_example(), 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") )) browsable(tags$div( use_pkg_gfont("henny-penny"), tag_example(), 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") )) }
if (interactive()) { library(gfonts) library(htmltools) browsable(tags$div( use_pkg_gfont("open-sans"), tag_example(), 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") )) browsable(tags$div( use_pkg_gfont("henny-penny"), tag_example(), 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") )) }