MarkusN
MarkusN

Reputation: 3223

Rmarkdown produces HTML-File with whole fontawesome library included

I have a reactable() table in which I want to use fontawesome icons as decoration.

Although I only use 4 icons, the whole fontawesome library is included in the HTML file. This file then becomes very large (approx. 5MB)

How can I define, that only the used icons have to be embedded in my HTML file?

Here is a minimal reprex:

---
title: "embedded_fa_icons"
output: html_document
---
  
```{r setup, include=FALSE}

library(reactable)
library(reactablefmtr)
library(palmerpenguins)
library(dplyr)

knitr::opts_chunk$set(echo = FALSE)
```

## Penguin stats

```{r penguin_data}

data <- sample_n(penguins, 50) %>% 
  filter(!is.na(bill_length_mm)) %>% 
  select(species, bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g)

```

```{r penguin_table_1, eval=TRUE}

reactable(
  data,
  columns = list(
    bill_length_mm = colDef(),
    bill_depth_mm = colDef(),
    flipper_length_mm = colDef(),
    body_mass_g = colDef()
  )
)

```

```{r penguin_table_2, eval=FALSE}
reactable(
  data,
  columns = list(
    bill_length_mm = colDef(cell = icon_sets(data, icons = c("ruler"))),
    bill_depth_mm = colDef(cell = icon_sets(data, icons = c("ruler-vertical"))),
    flipper_length_mm = colDef(cell = icon_sets(data, 
                                                icons = c("ruler-horizontal"))),
    body_mass_g = colDef(cell = icon_sets(data, 
                                          icons = c("balance-scale-left", 
                                                    "balance-scale", 
                                                    "balance-scale-right")))
  )
)
```

When I knit the document evaluating code block "penguin_table_1" the size of the resulting HTML file is (surprisingly big) 1 MB.

When I knit the coument evaluating code block "penguin_table_2" the file size increases to almost 5MB.

When I inspect the code, there is a line with >3 million characters representing the whole fontawesome library.

Upvotes: 2

Views: 46

Answers (0)

Related Questions