Use a font in Shiny or MarkdownSource:
Add an empty HTML element attached to an 'HTML Dependency' containing the css and the font files so that the font is available in the HTML page. Multiple families are supported.
The htmlDependency is defined with function
addGFontHtmlDependency(family = "Open Sans", subset = c("latin", "latin-ext"))
family name of a 'Google Fonts', for example, "Open Sans", "Roboto", "Fira Code" or "Fira Sans Condensed". Complete list is available with the following command:
::get_all_fonts()$family |> gfontsunlist() |> unique() |> sort()
font subset, a character vector, it defaults to only "latin" and "latin-ext" and can contains values such as "greek", "emoji", "chinese-traditional",
Run the following code to get a complete list:
::get_all_fonts()$subsets |> unlist() |> unique() |> sort()gfonts
It allows users to use fonts from 'Google Fonts' in an HTML page generated by 'shiny' or 'R Markdown'.
At the first request, the font files will be downloaded and stored in a cache on the
user's machine, thus avoiding many useless downloads or allowing to work with
these fonts afterwards without an Internet connection, in a docker image for example.
The server delivering the font files should not be too busy. That's
why a one second pause is added after each download to respect the server's
limits. This time can be set with the option
must be a number of seconds.