如何在 R Markdown 或闪亮的 DT 中显示列内图像?

H. *_*ong 1 r r-markdown shiny dt

---
title: "Untitled"
runtime: shiny
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
df <- data.frame(image = "http://www.ufotm.com/data/attachment/forum/201203/11/110705gf50r55yqcka5ffz.jpg", title = "here is a title")
DT::renderDataTable(df,
                escape = FALSE,
                rownames = FALSE,
                extensions = 'Buttons', options = list(
                    dom = 'lBfrtip',
                    buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
                    )
)
```
Run Code Online (Sandbox Code Playgroud)

我有图片网址。我尝试在 rmarkdown 或闪亮的应用程序中插入图像。我更喜欢DT图书馆,因为我可以下载 Excel 文件。我怎样才能做到这一点?

PS:我也想提供 Excel 或 pdf 文件供我的用户下载。

我尝试使用DataTables Options并找到相关问题。我尝试了下面的代码,它显示错误。

---
    title: "Untitled"
runtime: shiny
output: html_document
---

df <- data.frame(image = "http://www.ufotm.com/data/attachment/forum/201203/11/110705gf50r55yqcka5ffz.jpg", title = "here is a title")
DT::renderDataTable(df,
                    escape = FALSE,
                    rownames = FALSE,
                    extensions = 'Buttons', options = list(
                        dom = 'lBfrtip',
                        buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
                        columnDefs = list(list(targets = 1,
                                               data = "img",
                                               render = JS(
                                                   'function ( url, type, full) {',
                                                   'return '<img height="75%" width="75%" src="'+full[7]+'"/>';',
                                                   '}'
                                               )
                        ))
                    )
)
Run Code Online (Sandbox Code Playgroud)

SBi*_*sta 5

您可以使用 html 标签并按escape = FALSE如下方式使用:

---
title: "Untitled"
runtime: shiny
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
df <- data.frame(image = c('<img src="http://www.ufotm.com/data/attachment/forum/201203/11/110705gf50r55yqcka5ffz.jpg" height="52"></img>' ), title = "here is a title")
DT::renderDataTable(df, escape = FALSE)
```
Run Code Online (Sandbox Code Playgroud)

你会得到这样的东西: 在此输入图像描述