https://github.com/gadenbuie/metathis
  
  
     :information_source: <meta> tags and social media cards for R-made web things 
    https://github.com/gadenbuie/metathis
  
        Last synced: 3 months ago 
        JSON representation
    
:information_source: <meta> tags and social media cards for R-made web things
- Host: GitHub
 - URL: https://github.com/gadenbuie/metathis
 - Owner: gadenbuie
 - License: other
 - Created: 2019-07-29T04:08:45.000Z (over 6 years ago)
 - Default Branch: main
 - Last Pushed: 2024-01-15T13:38:51.000Z (almost 2 years ago)
 - Last Synced: 2025-06-30T07:20:16.904Z (4 months ago)
 - Language: R
 - Homepage: https://pkg.garrickadenbuie.com/metathis
 - Size: 5.24 MB
 - Stars: 67
 - Watchers: 2
 - Forks: 3
 - Open Issues: 5
 - 
            Metadata Files:
            
- Readme: README.Rmd
 - Changelog: NEWS.md
 - License: LICENSE
 
 
Awesome Lists containing this project
- jimsghstars - gadenbuie/metathis - :information_source: <meta> tags and social media cards for R-made web things (R)
 
README
          ---
output: github_document
always_allow_html: yes
---
```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```
[](https://CRAN.R-project.org/package=metathis)
[](https://gadenbuie.r-universe.dev/metathis)
[](https://lifecycle.r-lib.org/articles/stages.html)
[](https://github.com/gadenbuie/metathis/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/github/gadenbuie/metathis)
[rmarkdown]: https://rmarkdown.rstudio.com
[blogdown]: https://bookdown.org/yihui/blogdown
[Shiny]: https://shiny.posit.co/
[r4ds]: https://r4ds.had.co.nz/
[xaringan]: https://slides.yihui.org/xaringan
[bookdown]: https://bookdown.org/
[pagedown]: https://github.com/rstudio/pagedown
[htmltools]: https://github.com/rstudio/htmltools
[pkgdown]: https://pkgdown.r-lib.org
## Why metathis?
The goal of **metathis** is to help you add HTML `` tags to your [R Markdown][rmarkdown] and [Shiny] apps.
HTML `` tags provide browsers and social media with metadata about HTML pages.
Using `` 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 `` 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()`](http://pkg.garrickadenbuie.com/metathis/reference/meta_social.html) 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](https://CRAN.R-project.org) with:
``` r
# CRAN
install.packages("metathis")
```
And the development version from [Github](https://github.com/gadenbuie/metathis) or [r-universe](https://gadenbuie.r-universe.dev/builds) with:
``` r
# r-universe
install.packages("metathis", repos = "https://gadenbuie.r-universe.dev")
# install.packages("devtools")
devtools::install_github("gadenbuie/metathis@main")
```
## Works In
✅ [R Markdown][rmarkdown] HTML Documents  
✅ [Shiny] Apps  
✅ [xaringan]  
✅ [pagedown]  
✅ [bookdown]  
❌ [blogdown]1  
❌ [pkgdown]
`` tags can be added to ✅ packages with a standard R chunk
````markdown
```{r, echo=FALSE}`r ''`
meta() %>% 
  meta_description("My awesome presentation")
```
````
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 `` 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.)
````markdown
```{r blogdown-meta, echo = FALSE}`r ''`
meta() %>% 
  meta_description("A fantastic blog post") %>% 
  write_meta("meta.html")
```
````
## Example
### In R Markdown
This is a basic example that re-creates the `` tags for the [R for Data Science][r4ds] book. 
```{r library}
library(metathis)
```
```{r example, eval=FALSE}
meta() %>%
  meta_description(
    "This book will teach you how to do data science with R..."
  ) %>% 
  meta_name("github-repo" = "hadley/r4ds") %>% 
  meta_viewport() %>% 
  meta_social(
    title = "R for Data Science",
    url = "https://r4ds.had.co.nz",
    image = "https://r4ds.had.co.nz/cover.png",
    image_alt = "The cover of the R4DS book",
    og_type = "book",
    og_author = c("Garrett Grolemund", "Hadley Wickham"),
    twitter_card_type = "summary",
    twitter_creator = "@hadley"
  )
```
```{r example-print, echo=FALSE}
x <- 
<>
  
print(x)
```
### In Shiny Apps
To use `metathis` in Shiny apps, 
simply call `meta()` and related tags anywhere inside your page UI, 
for example inside `fluidPage()`.
```r
ui <- fluidPage(
  # Application title
  titlePanel("metathis Example"),
  
  meta() %>%
    meta_social(
      title = "metathis",
      description = " and social media cards for web things in R",
      url = "https://pkg.garrickadenbuie.com/metathis",
      image = "https://garrickadenbuie.com/apple-touch-icon-114x114.png",
      image_alt = "An image for social meda cards",
      twitter_creator = "@grrrck",
      twitter_card_type = "summary",
      twitter_site = "@grrrck"
  )
  # ... your UI ...
)
```
### In xaringan Slides
To use `metathis` in [xaringan] slides,
add `meta()` and related tags in a chunk anywhere in your slide's source `.Rmd` file.
This example is from a [presentation on the drake package](https://pkg.garrickadenbuie.com/drake-intro/).
````markdown
```{r meta, echo=FALSE}`r ''`
library(metathis)
meta() %>%
  meta_general(
    description = "A gentle introduction to reproducible data workflows with the {drake} package.",
    generator = "xaringan and remark.js"
  ) %>% 
  meta_name("github-repo" = "gadenbuie/drake-intro") %>% 
  meta_social(
    title = "Reproducible Data Workflows With Drake",
    url = "https://pkg.garrickadenbuie.com/drake-intro",
    image = "https://pkg.garrickadenbuie.com/drake-intro/assets/images/drake-intro-cover.jpg",
    image_alt = "The first slide of the Reproducible Data Workflows with drake presentation, featuring the drake hex logo and neatly ordered row of items on a desk (eraser, pencil, coffee cup, paperclips).",
    og_type = "website",
    og_author = "Garrick Aden-Buie",
    twitter_card_type = "summary_large_image",
    twitter_creator = "@grrrck"
  )
```
````
## Thanks
Thanks to [Josh Buchea](https://github.com/joshbuchea) for providing an [excellent and indispensable resource](https://github.com/joshbuchea/HEAD) on `` tags and other things that go in the HTML `` tags.
Thanks also to [Malcolm Barret](https://github.com/malcolmbarrett). 
Watching over his shoulder as he developed [ymlthis](https://ymlthis.r-lib.org) made putting this package together so much easier.
Finally, thanks to the [RStudio team](https://github.com/rstudio) and others who developed [htmltools](https://github.com/rstudio/htmltools) for making HTML in R a breeze.
```{r, echo=FALSE, warning=FALSE}
meta() %>%
  meta_description(
    " and social media cards for web things inR"
  ) %>% 
  meta_name("github-repo" = "gadenbuie/metathis") %>% 
  meta_social(
    title = "{metathis}",
    url = "https://pkg.garrickadenbuie.com/metathis",
    image = "https://pkg.garrickadenbuie.com/metathis/reference/figures/card.png",
    image_alt = "many  tags and the name of the R package: ",
    og_author = c("Garrick Aden-Buie"),
    twitter_card_type = "summary",
    twitter_creator = "@grrrck"
  ) %>% 
  include_meta()
```
---
### Notes
1. For adding meta tags to blogdown sites, [Socialize your blogdown by Xavier A](https://xvrdm.github.io/2017/10/23/socialize-your-blogdown/) is an excellent resource and you can use metathis to help discover the tags you need while following the instructions in the article.
        
