I've got a flexdashboard, and I need to embed a few videos.
With a static file path, it's pretty straightforward:
tags$video(
src = "sample.mp4",
type = "video/mp4",
width = 1280, height = 720,
controls = "controls"
)
But I can't figure out how to embed a video with a file path that includes an input/reactive value. This doesn't work:
renderUI({
req(rv())
tags$video(
src = rv(),
type = "video/mp4",
width = 1280, height = 720,
controls = "controls"
)
})
Here's an Rmd file with both examples:
---
title: "Test"
output:
flexdashboard::flex_dashboard:
runtime: shiny
---
```{r setup}
library(flexdashboard)
library(shiny)
```
Column
------
### Static
```{r}
tags$video(
src = "sample.mp4",
type = "video/mp4",
width = 1280, height = 720,
controls = "controls"
)
```
Column
------
```{r}
rv <- reactive({ "sample.mp4" })
```
### Reactive
```{r}
renderUI({
req(rv())
tags$video(
src = rv(),
type = "video/mp4",
width = 1280, height = 720,
controls = "controls"
)
})
```
Upon inspection, the "static" chunk generates this HTML:
<video src="file5450741f3ada_files/sample.mp4" type="video/mp4" width="1280" height="720" controls="controls"></video>
Wheres the "dynamic" chunk this:
<video src="sample.mp4" type="video/mp4" width="1280" height="720" controls="controls"></video>
It looks like tags$video
puts the file in a temporary folder, which doesn't happen when src
argument is a reactive value and/or inside renderUI
.
Any tips?