Functions to Embed Video in HTML

A set of functions for generating HTML to embed hosted video in your R Markdown documents or Shiny applications.

The goal of the vembedr package is to make it a little bit easier for you to embed videos into your rmarkdown documents and your shiny apps. Three services are currently supported: YouTube, Vimeo, and Microsoft Channel 9 (including UseR! 2016 and 2017 videos).

New to version 0.1.3

  • updates README to show some custom formatting, thanks Eric Koncina and Aurélien Ginolhac
  • adds function embed_user2017(): embed videos from UseR!2017


You can install the latest released version from CRAN with:


or the latest development version from GitHub with:



For these examples, it can be useful to load the htmltools package along with the vembedr package.


With the function embed_url(), you can use the URL from your browser to embed video:


If you just want the embedding code, the suggest_embed() function may be useful:

#> embed_youtube("uV4UpCq2azs") %>%
#>   use_start_time("1m32s")

All of the features shown here can be used for all the supported services: YouTube, Vimeo, and Channel 9. Here, the features are mixed-and-matched in the interest of brevity.

To embed a YouTube (or Vimeo, or Channel 9) video you can use its identifier, which you can get from the original URL.


For this example, we embed a Vimeo using some custom formatting - thanks to Eric Koncina and Aurélien Ginolhac who showed the way. First let's introduce some css where we can define some rounded corners for an embedded video, by describing an HTML class, vembedr:

.vembedr {
  display: inline-block;
  border-radius: 25px; /* adjust it to your needs */
  overflow: hidden;

.vembedr iframe {
  display: block;
  border: none;

To embed a Vimeo with some custom formatting:

  • call embed_vimeo() using the Vimeo identifier, then
  • wrap that in <div/> using our new vembedr class, then
  • wrap that in a <div/> that centers its contents
embed_vimeo("189919038") %>%
  div(class = "vembedr") %>%
  div(align = "center")

Of course, the use of the pipe operator is optional. Hat tip to Karthik Ram for tweeting out this Vimeo.

You can also specify a start time. Please note that for Vimeo, specifying a start time implies that the video will be auto-played (which can be annoying).

Here's an example using a lightning presentation from UseR!2017:

embed_user2017("Room-202-Lightning-Talks") %>% 

Note for GitHub README and RStudio viewer

The GitHub Markdown renderer does not support video embedding. To see everything in action, you are invited to visit the GitHub pages site, built using pkgdown.

If you use the RStudio-IDE viewer to preview your work, please note that RStudio have made the design choice not to allow arbitrary external web-content in the IDE, which is wholly appropriate. However, with the advent of the learnr package, the IDE-viewer supports embedding of Vimeo and YouTube videos.

Otherwise, you can simply open your preview in an external browser.

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.


vembedr 0.1.3

  • updates README to show some custom formatting (#25, thanks @koncina and @ginolhac)
  • deprecates hms() and secs() in favor of use_start_time() (#24)
  • adds function embed_user2017(): embed videos from UseR!2017
  • version bump for development

vembedr 0.1.2

  • adds embed_url(): given a URL, build the <iframe/> to embed the video
  • adds suggest_embed(): given a URL, provides suggested code to embed video
  • fully deprecates allow_full_screen argument
  • adds pkgdown support
  • version bump for development

vembedr 0.1.1

  • adds rickroll_channel9(), stretches definition of rickrolling
  • deprecates allow_full_screen argument to embed functions in favor of allowfullscreen - this will be more consistent with each service's API
  • adds use_start_time() for constent interface to all embed functions
  • adds embed_channel9() for Microsoft videos
  • adds support for start-time for Vimeo (#14, thanks @karthik for tip)
  • adds embed_user2016()
  • version bump for development

vembedr 0.1.0

  • Added a file to track changes to the package.
  • Added a vignette.
  • Added helper function secs() and query argument to both embed_vimeo() and embed_youtube().
  • Added functions rickroll_vimeo() and rickroll_youtube().
  • Added functions embed_vimeo() and embed_youtube().

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.1.3 by Ian Lyttle, 8 months ago

Report a bug at

Browse source code at

Authors: Ian Lyttle [aut, cre, cph], Schneider Electric [cph]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports htmltools, httr, stringr, magrittr

Suggests testthat, knitr, rmarkdown, covr

See at CRAN