以下 rmarkdown 创建了一个 Shiny 文档,其中包含一个可在浏览器中播放的 wav 文件的链接(使用 Chrome)。表中的第一个链接指向外部 wav 文件http://www.nch.com.au/acm/11k16bitpcm.wav,第二个链接指向与www
rmarkdown 相关的文件夹中的同一文件。第一个链接有效,第二个无效。根据我在网上找到的各种文章,该www
文件夹是此类外部内容的正确位置,事实上,如果我将png
文件放在那里,我可以使用img()
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"))
})
```
有没有人有任何提示可以帮助我使第二个链接正常工作并正确提供音频?