Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embed_youtube(width = 'auto', height = 'auto') #62

Open
englianhu opened this issue Mar 21, 2022 · 0 comments
Open

embed_youtube(width = 'auto', height = 'auto') #62

englianhu opened this issue Mar 21, 2022 · 0 comments

Comments

@englianhu
Copy link

I think our default should be to embed using defaults:

height = 300 width = NULL ratio = c("16by9", "4by3")

For the <iframe/> itself, we need the width and height, but we can calculate this if we have two of the three values - if we have all three, we ignore ratio.

This begs an internal function:

get_width_height <- function(width, height, ratio) {

  # validate ratio

  if (is.null(width) && is.null(height)) {
    stop() # no can do
  }

  if (is.null(width)) {
    width <- round(height * ratio)
  }

  if (is.null(height)) {
    height <- round(width / ratio)
  }

  list(width = width, height = height)
}

Source : #33 (comment)

>args(embed_youtube)
function (id, width = NULL, height = 300, ratio = c("16by9", 
    "4by3"), frameborder = 0, allowfullscreen = TRUE, query = NULL) 
NULL
<environment: R_GlobalEnv>
>
>lib('vembedr'); vlist <- c('C1hrbXlreY4', 'O8qPQNz8Q8Y', '3pnXMEusQCY', 'E9_eAm2tTns', 'budv9DSiuko')
> 
> embed_youtube(vlist[1], height='auto')
Error in height * ratio : 二进列运算符中有非数值参数
> 
> embed_youtube(vlist[1], width='auto')
错误: width is not a number (a length one numeric vector).
> 
> embed_youtube(vlist[1], width='auto', height='auto')
错误: width is not a number (a length one numeric vector).

Raised Issue for Enhancement

  1. How to make the embed video auto-resize when the browser screen width/height resize.

  2. With regards rmarkdown, let say embed multiple videos by html as below, there can be ordered in one line...

<iframe width="560" height="315" src="https://www.youtube.com/embed/O8qPQNz8Q8Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <iframe width="560" height="315" src="https://www.youtube.com/embed/O8qPQNz8Q8Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

but use vembedr on rmarkdown...

Screenshot_4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant