Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Font-Awesome Icons in Rmarkdown Docs #813

Closed
tiernanmartin opened this issue Sep 21, 2016 · 9 comments
Closed

Feature Request: Font-Awesome Icons in Rmarkdown Docs #813

tiernanmartin opened this issue Sep 21, 2016 · 9 comments
Milestone

Comments

@tiernanmartin
Copy link

I've noticed that it's currently quite complicated to insert font-awesome icons in Rmarkdown documents.

Could this be made easier somehow? It's so straight-forward in shiny...

Thanks!

@jjallaire
Copy link
Member

font-awesome is actually now included in the rmarkdown package (we use it for icons on the navbar for R Markdown websites). You can currently force it to be included in the document with the following code:

```{r, include=FALSE}
htmltools::tagList(rmarkdown::html_dependency_font_awesome())
```

But of course we should make this much more straightforward!

@tiernanmartin
Copy link
Author

This solution doesn't seem to be working correctly. Did I misunderstand your suggestion, @jjallaire ?

---
output: html_document
---

#```{r setup, include=FALSE}
htmltools::tagList(rmarkdown::html_dependency_font_awesome())
#```

#```{r}
shiny::icon('file',lib = "font-awesome")
#```

##Error: path for html_dependency not provided
##Execution halted

@jjallaire
Copy link
Member

My solution is intended to allow you to add font awesome classes directly to e.g. <i> tags rather than to use the shiny::icon function, e.g. this works:

---
output: html_document
---

```{r setup, include=FALSE}
htmltools::tagList(rmarkdown::html_dependency_font_awesome())
```

<i class="fa fa-file"></i>

@tiernanmartin
Copy link
Author

Got it – thanks for the clarification!

@walmes
Copy link

walmes commented Jan 2, 2017

This can also be used with bookdown html based documents. To accomplish I include the chunk below. The fontawesome-webfont.ttfmust be included as an attachment to render.

```{r, include = FALSE, eval = knitr::opts_knit$get("rmarkdown.pandoc.to") == "html"}
# Enables Font Awesome in HTML based bookdown outputs.
fa <- rmarkdown::html_dependency_font_awesome()
fa$attachment <- "fonts/fontawesome-webfont.ttf"
htmltools::tagList(fa)
```

Bests.

@yihui yihui added this to the v1.7 milestone Sep 1, 2017
@yihui
Copy link
Member

yihui commented Sep 1, 2017

@walmes Interesting. fontawesome-webfont.ttf is included in bookdown: https://github.com/rstudio/bookdown/tree/master/inst/resources/gitbook/css/fontawesome So in theory, you don't need to add it in the HTML dependency.

@jtr13
Copy link

jtr13 commented Nov 4, 2019

Worked for me in bookdown exactly as @jjallaire and @yihui stated, without attaching the .ttf file.

@ferroao
Copy link

ferroao commented Feb 17, 2020

Here is a workaround if you do not want the 5Mb added by (rmarkdown::html_dependency_font_awesome()).

In yaml:

output:
  html_document:
    includes:
      in_header: myheader.html

setup chunk: (get url of .js in https://fontawesome.com/v4.7.0/get-started/ )

    ```{r setup, include=FALSE}
    #Create myheader.html
    fileConn <- file("myheader.html")
    writeLines('<script src="https://kit.fontawesome.com/<get In Link>.js" crossorigin="anonymous"></script>', fileConn)
    close(fileConn)
    ```

works great for fontawesome 4. For 5, you need to register one .js for each project

@github-actions
Copy link

github-actions bot commented Nov 3, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants