无法在 rmarkdown Shiny 应用程序中播放 handsontable 中嵌入的本地音频
Cannot play local audio embedded in handsontable within rmarkdown Shiny app
以下 rmarkdown 创建了一个 Shiny 文档,其中包含 handsontable 和 links 到可以在浏览器中播放的 wav 文件(使用 Chrome)。 table 中的第一个 link 指向一个外部 wav 文件 http://www.nch.com.au/acm/11k16bitpcm.wav,第二个 link 指向相对于 www
文件夹中的同一个文件降价。第一个 link 有效,第二个无效。根据我在网上找到的各种文章,www
文件夹是此类外部内容的正确位置,事实上,如果我将 png
文件放在那里,我可以在rmarkdown 让 Shiny 正确显示图像。
---
title: "Playing audio in handsontable"
date: "18 August 2016"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shiny)
library(rmarkdown)
library(rhandsontable)
library(dplyr)
links = c('<audio controls preload="none" type="audio/wav" src="http://www.nch.com.au/acm/11k16bitpcm.wav" </audio>',
'<audio controls preload="none" type="audio/wav" src="www/11k16bitpcm.wav" </audio>')
toDisplay = data.frame(Listen = links)
```
The first entry in this table refers to an external WAV file <http://www.nch.com.au/acm/11k16bitpcm.wav> and can be played in a browser. The second entry refers to the same file called `11k16bitpcm.wav` located in the folder `www` relative to the markdown but cannot be played. As a check, if the file can be seen from the markdown, the following will be TRUE: `r file.exists("www/11k16bitpcm.wav")`.
```{r tabsets, echo=FALSE}
renderRHandsontable({
rhandsontable(toDisplay, readOnly = TRUE, allowedTags = "<em><b><strong><a><big><audio>", rowHeaders = TRUE) %>%
hot_cols(columnSorting = T) %>%
hot_col(1, renderer = "html") %>%
hot_col(1, renderer = htmlwidgets::JS("safeHtmlRenderer"))
})
```
有没有人有任何提示可以帮助我让第二个 link 工作并正确提供音频?
shiny 包中的函数 addResourcePath 就是答案。
这是带有适当调用的代码。
---
title: "Playing audio in handsontable"
date: "18 August 2016"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shiny)
library(rmarkdown)
library(rhandsontable)
library(dplyr)
links = c('<audio controls preload="none" type="audio/wav" src="http://www.nch.com.au/acm/11k16bitpcm.wav" </audio>',
'<audio controls preload="none" type="audio/wav" src="www/11k16bitpcm.wav" </audio>')
toDisplay = data.frame(Listen = links)
# this declares a path containing the resource
addResourcePath("www", "www")
```
The first entry in this table refers to an external WAV file <http://www.nch.com.au/acm/11k16bitpcm.wav> and can be played in a browser. The second entry refers to the same file called `11k16bitpcm.wav` located in the folder `www` relative to the markdown but cannot be played unless a call to `shiny::addResourcePath()` is made. As a check, if the file can be seen from the markdown, the following will be TRUE: `r file.exists("www/11k16bitpcm.wav")`.
```{r tabsets, echo=FALSE}
renderRHandsontable({
rhandsontable(toDisplay, readOnly = TRUE, allowedTags = "<em><b><strong><a><big><audio>", rowHeaders = TRUE) %>%
hot_cols(columnSorting = T) %>%
hot_col(1, renderer = "html") %>%
hot_col(1, renderer = htmlwidgets::JS("safeHtmlRenderer"))
})
```
以下 rmarkdown 创建了一个 Shiny 文档,其中包含 handsontable 和 links 到可以在浏览器中播放的 wav 文件(使用 Chrome)。 table 中的第一个 link 指向一个外部 wav 文件 http://www.nch.com.au/acm/11k16bitpcm.wav,第二个 link 指向相对于 www
文件夹中的同一个文件降价。第一个 link 有效,第二个无效。根据我在网上找到的各种文章,www
文件夹是此类外部内容的正确位置,事实上,如果我将 png
文件放在那里,我可以在rmarkdown 让 Shiny 正确显示图像。
---
title: "Playing audio in handsontable"
date: "18 August 2016"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shiny)
library(rmarkdown)
library(rhandsontable)
library(dplyr)
links = c('<audio controls preload="none" type="audio/wav" src="http://www.nch.com.au/acm/11k16bitpcm.wav" </audio>',
'<audio controls preload="none" type="audio/wav" src="www/11k16bitpcm.wav" </audio>')
toDisplay = data.frame(Listen = links)
```
The first entry in this table refers to an external WAV file <http://www.nch.com.au/acm/11k16bitpcm.wav> and can be played in a browser. The second entry refers to the same file called `11k16bitpcm.wav` located in the folder `www` relative to the markdown but cannot be played. As a check, if the file can be seen from the markdown, the following will be TRUE: `r file.exists("www/11k16bitpcm.wav")`.
```{r tabsets, echo=FALSE}
renderRHandsontable({
rhandsontable(toDisplay, readOnly = TRUE, allowedTags = "<em><b><strong><a><big><audio>", rowHeaders = TRUE) %>%
hot_cols(columnSorting = T) %>%
hot_col(1, renderer = "html") %>%
hot_col(1, renderer = htmlwidgets::JS("safeHtmlRenderer"))
})
```
有没有人有任何提示可以帮助我让第二个 link 工作并正确提供音频?
shiny 包中的函数 addResourcePath 就是答案。
这是带有适当调用的代码。
---
title: "Playing audio in handsontable"
date: "18 August 2016"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(shiny)
library(rmarkdown)
library(rhandsontable)
library(dplyr)
links = c('<audio controls preload="none" type="audio/wav" src="http://www.nch.com.au/acm/11k16bitpcm.wav" </audio>',
'<audio controls preload="none" type="audio/wav" src="www/11k16bitpcm.wav" </audio>')
toDisplay = data.frame(Listen = links)
# this declares a path containing the resource
addResourcePath("www", "www")
```
The first entry in this table refers to an external WAV file <http://www.nch.com.au/acm/11k16bitpcm.wav> and can be played in a browser. The second entry refers to the same file called `11k16bitpcm.wav` located in the folder `www` relative to the markdown but cannot be played unless a call to `shiny::addResourcePath()` is made. As a check, if the file can be seen from the markdown, the following will be TRUE: `r file.exists("www/11k16bitpcm.wav")`.
```{r tabsets, echo=FALSE}
renderRHandsontable({
rhandsontable(toDisplay, readOnly = TRUE, allowedTags = "<em><b><strong><a><big><audio>", rowHeaders = TRUE) %>%
hot_cols(columnSorting = T) %>%
hot_col(1, renderer = "html") %>%
hot_col(1, renderer = htmlwidgets::JS("safeHtmlRenderer"))
})
```