Why metathis?

The goal of metathis is to help you add HTML <meta> tags to your R Markdown and Shiny apps.

HTML <meta> tags provide browsers and social media with metadata about HTML pages. Using <meta> tags will help your users find your articles, Shiny apps, and presentations, and will help you make sure they look great in social media timelines.

metathis makes the process of adding these tags to your R Markdown pages and Shiny apps easier by using the htmltools package to add <meta> tags as a dependency, added directly to the document in an R code chunk or your Shiny app UI rather than requiring you to adjust templates or write additional files.

If you want great looking social media cards, the meta_social() function will help you add everything you need for Twitter, Facebook and other social media sites that support the Open Graph protocol.

Installation

You can install the latest version of metathis from CRAN with:

install.packages("metathis")

And the development version from Github with:

Works In

R Markdown HTML Documents
Shiny Apps
xaringan
pagedown
bookdown
blogdown1
pkgdown

<meta> tags can be added to ✅ packages with a standard R chunk

For other packages or situations, you can use include_meta() to explicitly declare the meta tags as an html dependency or use write_meta() to save the <meta> tags to an .html file that can be included via includes: in_header. (In blogdown, consult your blogdown/hugo theme for the correct inclusion method.)

Example

In R Markdown

This is a basic example that re-creates the <meta> tags for the R for Data Science book.

library(metathis)

Thanks

Thanks to Josh Buchea for providing an excellent and indispensable resource on <meta> tags and other things that go in the HTML <head> tags.

Thanks also to Malcolm Barret. Watching over his shoulder as he developed ymlthis made putting this package together so much easier.

Finally, thanks to the RStudio team and others who developed htmltools for making HTML in R a breeze.


Notes

  1. For adding meta tags to blogdown sites, Socialize your blogdown by Xavier A is an excellent resource and you can use metathis to help discover the tags you need while following the instructions in the article.