• Stars
    star
    294
  • Rank 138,878 (Top 3 %)
  • Language
    R
  • License
    Other
  • Created about 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easily insert FontAwesome icons into R Markdown docs and Shiny apps


CRAN status R build status Package Site Coverage status

The project has reached a stable, usable state and is being actively developed. Monthly Downloads Total Downloads

Contributor Covenant


The fontawesome R package makes it very easy to insert Font Awesome icons into R Markdown documents and Shiny apps (or, anywhere else you need to put them).

Examples

The fa() function can be used to insert an FA icon. For example, we can get the r-project icon in steelblue:

fa(name = "r-project", fill = "steelblue")
#> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 581 512" class="rfa" style="height:0.75em;fill:steelblue;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>

As can be seen, what we really get from the function is an SVG object that represents the icon. This can be directly used within R Markdown with:

{text} `r fa(...)` {text}

Font Awesome SVG icons are great to use instead of <i> tags + font files for a few reasons:

  • There is less overhead in a Shiny app or R Markdown document since an <i> tag requires computation to obtain the icon (<svg> tags represent the actual icon)
  • Using <i> tags has a 'being online' requirement since network activity is necessary for resolving these tags (SVGs in fontawesome are stored in the package, so, no Internet connectivity is necessary for that)
  • There are styling options available for SVG that aren't there for icon fonts

R Markdown

Here is an example R Markdown document that includes Font Awesome icons:

---
title: "Font Awesome in R Markdown"
output: html_document
---

```{r load_packages, message=FALSE, warning=FALSE, include=FALSE} 
library(fontawesome)
```

# Just a few tests with `r fa("font-awesome-logo-full", fill = "forestgreen")`

It works well in headings...

# `r fa("r-project", fill = "steelblue")` H1 Heading

## `r fa("r-project", fill = "steelblue")` H2 Heading

### `r fa("r-project", fill = "steelblue")` H3 Heading

#### `r fa("r-project", fill = "steelblue")` H4 Heading

##### `r fa("r-project", fill = "steelblue")` H5 Heading

...and works equally well within inline text: `r fa("r-project", fill = "steelblue")`.

This will appear, when knit, as:

Shiny

Hereโ€™s a Shiny app (from the Shiny Gallery) thatโ€™s been slightly modified to incorporate Font Awesome icons in the text above the three search fields:

library(shiny)
library(DT)
library(ggplot2)
library(fontawesome)

ui <- fluidPage(

  titlePanel("Basic DataTable"),

  # Create a new Row in the UI for selectInputs
  fluidRow(

    column(
      width = 4,
      selectInput(
        inputId = "man",
        label = tags$p(fa("car", fill = "purple"), "Manufacturer:"),
        choices = c(
          "All",
          unique(as.character(mpg$manufacturer))))
    ),

    column(
      width = 4,
      selectInput(
        inputId = "trans",
        label = tags$p(fa("car", fill = "forestgreen"), "Transmission:"),
        choices = c(
          "All",
          unique(as.character(mpg$trans))))
    ),

    column(
      width = 4,
      selectInput(
        inputId = "cyl",
        label = tags$p(fa("car", fill = "steelblue"), "Cylinders:"),
        choices = c(
          "All",
          unique(as.character(mpg$cyl))))
    )
  ),

  # Create a new row for the table.
  fluidRow(
    dataTableOutput("table")
  )
)

server <- function(input, output) {

  # Filter data based on selections
  output$table <- renderDataTable({

    data <- mpg
    if (input$man != "All") {
      data <- data[data$manufacturer == input$man,]
    }
    if (input$cyl != "All") {
      data <- data[data$cyl == input$cyl,]
    }
    if (input$trans != "All") {
      data <- data[data$trans == input$trans,]
    }
    data
  })
}

shinyApp(ui = ui, server = server)

The Shiny app will look something like this:

Please note that using shiny::icon() in place of fontawesome::fa() will still work. Internally, the icon() function will call fontawesome's fa_i() function, which generates an old-school <i> tag for the icon.

Installation

Want to try this out? The fontawesome package can be installed from CRAN:

install.packages("fontawesome")

Also, you can install the development version of fontawesome from GitHub:

devtools::install_github("rstudio/fontawesome")

If you encounter a bug, have usage questions, or want to share ideas to make this package better, feel free to file an issue.

Code of Conduct

Please note that the rstudio/fontawesome project is released with a contributor code of conduct.
By participating in this project you agree to abide by its terms.

๐Ÿ›๏ธ Governance

This project is primarily maintained by Rich Iannone. Other authors may occasionally assist with some of these duties.

More Repositories

1

cheatsheets

Posit Cheat Sheets - Can also be found at https://posit.co/resources/cheatsheets/.
TeX
5,673
star
2

shiny

Easy interactive web applications with R
R
5,281
star
3

rstudio

RStudio is an integrated development environment (IDE) for R
Java
4,432
star
4

bookdown

Authoring Books and Technical Documents with R Markdown
JavaScript
3,690
star
5

rmarkdown

Dynamic Documents for R
R
2,737
star
6

gt

Easily generate information-rich, publication-quality tables from R
R
1,951
star
7

shiny-examples

JavaScript
1,945
star
8

blogdown

Create Blogs and Websites with R Markdown
R
1,710
star
9

reticulate

R Interface to Python
R
1,649
star
10

webinars

Code and slides for RStudio webinars
HTML
1,510
star
11

rticles

LaTeX Journal Article Templates for R Markdown
TeX
1,402
star
12

plumber

Turn your R code into a web API.
R
1,374
star
13

tensorflow

TensorFlow for R
R
1,322
star
14

renv

renv: Project environments for R.
R
975
star
15

pagedown

Paginate the HTML Output of R Markdown with CSS for Print
R
873
star
16

shinydashboard

Shiny Dashboarding framework
CSS
852
star
17

pointblank

Data quality assessment and metadata reporting for data frames and database tables
R
845
star
18

keras3

R Interface to Keras
R
830
star
19

flexdashboard

Easy interactive dashboards for R
JavaScript
804
star
20

leaflet

R Interface to Leaflet Maps
JavaScript
793
star
21

rmarkdown-book

R Markdown: The Definitive Guide (published by Chapman & Hall/CRC in July 2018)
RMarkdown
738
star
22

ggvis

Interactive grammar of graphics for R
R
709
star
23

shiny-server

Host Shiny applications over the web.
JavaScript
707
star
24

learnr

Interactive Tutorials with R Markdown
R
704
star
25

rstudio-conf

Materials for rstudio::conf
HTML
699
star
26

RStartHere

A guide to some of the most useful R Packages that we know about
R
661
star
27

py-shiny

Shiny for Python
Python
627
star
28

DT

R Interface to the jQuery Plug-in DataTables
JavaScript
587
star
29

rmarkdown-cookbook

R Markdown Cookbook. A range of tips and tricks to make better use of R Markdown.
RMarkdown
568
star
30

blastula

Easily send great-looking HTML email messages from R
R
541
star
31

r2d3

R Interface to D3 Visualizations
R
514
star
32

bookdown-demo

A minimal book example using bookdown
CSS
476
star
33

hex-stickers

RStudio hex stickers
R
448
star
34

bslib

Tools for theming Shiny and R Markdown via Bootstrap 3, 4, or 5.
SCSS
446
star
35

distill

Distill for R Markdown
HTML
419
star
36

packrat

Packrat is a dependency management system for R
R
394
star
37

tufte

Tufte Styles for R Markdown Documents
R
385
star
38

dygraphs

R interface to dygraphs
JavaScript
364
star
39

revealjs

R Markdown Format for reveal.js Presentations
JavaScript
316
star
40

pins-r

Pin, Discover and Share Resources
R
302
star
41

profvis

Visualize R profiling data
JavaScript
285
star
42

crosstalk

Inter-htmlwidget communication for R (with and without Shiny)
JavaScript
284
star
43

config

config package for R
R
247
star
44

tinytex-releases

Windows/macOS/Linux binaries and installation methods of TinyTeX
PowerShell
245
star
45

pool

Object Pooling in R
R
244
star
46

thematic

Theme ggplot2, lattice, and base graphics based on a few simple settings.
R
241
star
47

Intro

Course materials for "Introduction to Data Science with R", a video course by RStudio and O'Reilly Media
R
234
star
48

shinytest

Automated testing for shiny apps
JavaScript
224
star
49

shinymeta

Record and expose Shiny app logic using metaprogramming
R
222
star
50

nomnoml

Sassy 'UML' Diagrams for R
JavaScript
218
star
51

httpuv

HTTP and WebSocket server package for R
C
217
star
52

shinyuieditor

A GUI for laying out a Shiny application that generates clean and human-readable UI code
JavaScript
211
star
53

htmltools

Tools for HTML generation and output
R
201
star
54

promises

A promise library for R
R
195
star
55

vetiver-r

Version, share, deploy, and monitor models
R
177
star
56

rstudioapi

Safely access RStudio's API (when available)
R
161
star
57

gradethis

Tools for teachers to use with learnr
R
160
star
58

concept-maps

Concept maps for all things data science
HTML
158
star
59

master-the-tidyverse

Course contents for Master the Tidyverse
155
star
60

shinythemes

Themes for Shiny
R
152
star
61

chromote

Chrome Remote Interface for R
R
152
star
62

ShinyDeveloperConference

Materials collected from the First Shiny Developer Conference Palo Alto, CA January 30-31 2016
HTML
152
star
63

shiny-gallery

Code and other documentation for apps in the Shiny Gallery โœจ
HTML
145
star
64

sortable

R htmlwidget for Sortable.js
R
124
star
65

reactlog

Shiny Reactivity Visualizer
JavaScript
121
star
66

rsconnect

Publish Shiny Applications, RMarkdown Documents, Jupyter Notebooks, Plumber APIs, and more
R
120
star
67

redx

dynamic nginx configuration
Lua
118
star
68

r-docker

Docker images for R
Dockerfile
117
star
69

bigdataclass

Two-day workshop that covers how to use R to interact databases and Spark
R
114
star
70

r-system-requirements

System requirements for R packages
Shell
111
star
71

shinyapps

Deploy Shiny applications to ShinyApps
110
star
72

webshot2

Take screenshots of web pages from R
R
109
star
73

shinyloadtest

Tools for load testing Shiny applications
HTML
108
star
74

shinyvalidate

Input validation package for the Shiny web framework
JavaScript
108
star
75

shinytest2

R
102
star
76

miniUI

R
102
star
77

sass

Sass compiler package for R
C++
102
star
78

keras-customer-churn

Customer Churn Shiny Application
R
99
star
79

r-builds

an opinionated environment for compiling R
Shell
92
star
80

r-manuals

A re-styled version of the R manuals
R
87
star
81

addinexamples

An R package showcasing how RStudio addins can be registered and used.
R
85
star
82

shinyapps-package-dependencies

Collection of bash scripts that install R package system dependencies
R
74
star
83

markdown

The first generation of Markdown rendering for R (born in 2012). Originally based on the C library sundown. Now based on commonmark. Note that this package is markdown, not *rmarkdown*.
R
72
star
84

R-Websockets

HTML 5 Websockets implementation for R
R
68
star
85

webdriver

WebDriver client in R
R
68
star
86

beyond-dashboard-fatigue

Materials for the RStudio webinar 'Beyond Dashboard Fatigue'
R
66
star
87

cloudml

R interface to Google Cloud Machine Learning Engine
R
65
star
88

rstudio-docker-products

Docker images for RStudio Professional Products
Shell
62
star
89

shinylive

Run Shiny on Python (compiled to wasm) in the browser
TypeScript
61
star
90

rstudio-conf-2022-program

rstudio::conf(2022, "program")
R
60
star
91

bookdown.org

Source documents to generate the bookdown.org website
R
59
star
92

vetiver-python

Version, share, deploy, and monitor models.
Python
58
star
93

education.rstudio.com

CSS
57
star
94

tfestimators

R interface to TensorFlow Estimators
R
57
star
95

connections

https://rstudio.github.io/connections/
R
54
star
96

tfprobability

R interface to TensorFlow Probability
R
54
star
97

sparkDemos

HTML
53
star
98

shiny-incubator

Examples and ideas that don't belong in the core Shiny package and aren't officially supported.
JavaScript
53
star
99

swagger

Swagger is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
HTML
51
star
100

leaflet.mapboxgl

Extends the R Leaflet package with a Mapbox GL JS plugin to allow easy drawing of vector tile layers.
R
49
star