2

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?

Mikhail
  • 1,326
  • 6
  • 22
  • 29
  • What exactly do you mean by "doesn't work". Are you sure the `input$date` is formatted correctly to produce the correct path? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Jan 17 '20 at 15:56
  • Done. Does it make more sense now? – Mikhail Jan 19 '20 at 13:40
  • I thought I'd make it work using addResourcePath() as suggested at https://stackoverflow.com/a/39380988/17216 but it only worked on my local machine. When I tun the document on a shiny server I get a 404 error, i.e. the file isn't found. – Mikhail Jan 22 '20 at 10:33

0 Answers0