Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Markdown Add Tag to Head of HTML Output

Tags:

r

r-markdown

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>
like image 461
Ian Wesley Avatar asked Apr 10 '17 17:04

Ian Wesley


People also ask

How do you make a header in R Markdown?

We can insert headings and subheadings in R Markdown using the pound sign # . There are six heading/subheading sizes in R Markdown. The number of pound signs before your line of text determines the heading size, 1 being the largest heading and 6 being the smallest.

How do I add output in R Markdown?

If you prefer to use the console by default for all your R Markdown documents (restoring the behavior in previous versions of RStudio), you can make Chunk Output in Console the default: Tools -> Options -> R Markdown -> Show output inline for all R Markdown documents .

How do I embed code in R Markdown?

You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I ( Cmd + Option + I on macOS).

How do you add a table of contents to a RMD?

You can embed an R code chunk like this: ```{r} summary(cars) ``` You can also embed plots, for example: ```{r, echo=FALSE} plot(cars) ``` ### Header 3 Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. I tried running this in RStudio v 0.98.


Video Answer


2 Answers

Use library(metathis) !

Then include with:

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

And any other meta tag

like image 150
IVIM Avatar answered Oct 19 '22 12:10

IVIM


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)
```
like image 22
Marcelo Avatar answered Oct 19 '22 12:10

Marcelo