首页 > 解决方案 > R flexdashboard:如何在文件路径中嵌入具有反应值的视频?

问题描述

我有一个flexdashboard,我需要嵌入一些视频。

使用静态文件路径,它非常简单:

tags$video(
    src = "sample.mp4",
    type = "video/mp4",
    width = 1280, height = 720,
    controls = "controls"
)

但我不知道如何使用包含输入/反应值的文件路径嵌入视频。这不起作用:

renderUI({
    req(rv())

    tags$video(
        src = rv(),
        type = "video/mp4",
        width = 1280, height = 720,
        controls = "controls"
    )
})

这是一个包含两个示例的 Rmd 文件:

---
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"
    )
})
```

经检查,“静态”块生成以下 HTML:

<video src="file5450741f3ada_files/sample.mp4" type="video/mp4" width="1280" height="720" controls="controls"></video>

“动态”块在哪里:

<video src="sample.mp4" type="video/mp4" width="1280" height="720" controls="controls"></video>

看起来像是将文件放在一个临时文件夹中,当参数是反应值和/或 insidetags$video时,不会发生这种情况。srcrenderUI

有小费吗?

标签: rshinyhtml5-videoflexdashboard

解决方案


推荐阅读