12

How do I add an HTML meta tag within the head of an RMarkdown HTML output file from RStudio?

In particular I am trying to insert the following to over come IE compatibility issues on our intranet.

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
Ian Wesley
  • 3,565
  • 15
  • 34
  • The discussion in the comments here might help: http://stackoverflow.com/questions/19748205/insert-tags-in-header-via-rmd – Martin Schmelzer Apr 10 '17 at 20:12
  • 1
    I looked at that, but I do not believe it is helpful... – Ian Wesley Apr 10 '17 at 20:37
  • 1
    When I did this it had to be added as the very first `` tag, see this post: https://stackoverflow.com/questions/44009148/add-x-ua-compatible-in-rmarkdown-html-output/54676307#54676307 – Oliver Feb 13 '19 at 17:39

2 Answers2

10

You can create a file with the meta tag and add using the following YAML option:

---
title: "mytitle"
output:
  html_document:
    includes:
       in_header: myheader.html
---

You could also create the myheader.html file on the fly in the setup chunck:

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE )
#libraries
require(ggplot2)

#Create myheader.html
fileConn <- file("myheader.html")
writeLines('<meta http-equiv="X-UA-Compatible" content="IE=edge" />', fileConn)
close(fileConn)
```
Marcelo
  • 4,234
  • 1
  • 18
  • 18
  • Do you know if there's any way of providing a string value to `in_header` rather than a file path? The reason I ask is [in an attempt to solve an analogous problem](https://stackoverflow.com/questions/61528612/how-to-include-font-face-within-style-tag-of-rmarkdown) I will try to provide a string value to `in_header` (in my case, a ` – stevec May 01 '20 at 04:31
4

Use library(metathis) !

Then include with:

```{r include=F}
meta() %>%
  meta_description("My awesome App")
```

And any other meta tag

IVIM
  • 2,167
  • 1
  • 15
  • 41
  • It might be great to add the more general case that is very useful today, "property"/"content" tags like og tags . . . . . . meta_tag( "property"="og:title", content="--your title--" ) – Mike M Oct 28 '21 at 00:39