-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathREADME.Rmd
163 lines (112 loc) · 4.8 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
---
output:
github_document:
html_preview: false
---
# vebmedr
[](https://cran.r-project.org/package=vembedr)
[](https://travis-ci.org/ijlyttle/vembedr)
[](https://www.tidyverse.org/lifecycle/#maturing)
```{r, echo = FALSE}
library("htmltools")
library("vembedr")
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
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. Four services are currently supported:
- YouTube
- Vimeo
- Microsoft Channel 9 (including UseR! 2016 and 2017 videos).
- Box
## New to version 0.1.3.9000
- functions to help you format: `use_rounded()`, `use_align()`, and `use_bs_responsive()`.
- you can embed videos hosted on Box, using `embed_box()`.
## Installation
You can install the latest released version from CRAN with:
```{r eval=FALSE}
install.packages("vembedr")
```
or the latest development version from GitHub with:
```{r eval=FALSE}
# install.packages("devtools")
devtools::install_github("ijlyttle/vembedr")
```
### Documentation
This project supports two documentation-websites, built using [pkgdown](https://pkgdown.r-lib.org):
- [CRAN version](https://ijlyttle.github.io/vembedr)
- latest [developent version](https://ijlyttle.github.io/vembedr/dev) from GitHub
## Examples
For these examples, it can be useful to load the **htmltools** package along with the **vembedr** package.
```{r}
library("htmltools")
library("vembedr")
```
With the function `embed_url()`, you can use the URL from your browser to embed video:
```{r}
embed_url("https://www.youtube.com/watch?v=uV4UpCq2azs")
```
-----
If you just want the embedding code, the `suggest_embed()` function may be useful:
```{r}
suggest_embed("https://youtu.be/uV4UpCq2azs?t=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.
```{r}
embed_youtube("1-vcErOPofQ")
```
-----
For this example, we embed a Vimeo using some custom formatting - thanks to [Eric Koncina](https://github.com/koncina) and [Aurélien Ginolhac](https://github.com/ginolhac) who [showed the way](https://github.com/ijlyttle/vembedr/issues/25). First let's introduce some css where we can define some rounded corners for an embedded video, by describing an HTML class, `vembedr`:
```{css}
.vembedr {
display: inline-block;
border-radius: 25px; /* adjust it to your needs */
overflow: hidden;
}
.vembedr iframe {
display: block;
border: none;
}
```
```{css}
.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
```{r}
embed_vimeo("189919038") %>%
div(class = "vembedr") %>%
div(align = "center")
```
```{r echo=FALSE}
tags$br()
```
Of course, the use of the pipe operator is optional. Hat tip to Karthik Ram for [tweeting](https://twitter.com/_inundata/status/794616331727294464) 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:
```{r}
embed_user2017("Room-202-Lightning-Talks") %>%
use_start_time("26m35s")
```
------
## 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](http://ijlyttle.github.io/vembedr/) site, built using [pkgdown](http://hadley.github.io/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](https://rstudio.github.io/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](CONDUCT.md). By participating in this project you agree to abide by its terms.