带有图像的多个 Kable 表

Cur*_*ing 3 r ms-word r-markdown kableextra kable

我正在尝试使用kablecsv 文件创建多个表,但要求是我还需要按照下图将图像放入表中。整个图像需要在左列中。这可能吗?

样本输出

数据框如下所示:

df<-data.frame(Amount= c('$25', '$45', '$75'), 
               Rate = c('1%', '1%', '3%'), 
               Location = c('Germany', 'Switzerland', 'England'),
               ImageName= c('GE.png', 'BE.png', 'CE.png'),
               Status = c('Sold','Unsold','Sold')
               )
Run Code Online (Sandbox Code Playgroud)

到目前为止,我的 R 代码是

---
output: 
  word_document:
    reference_docx: ReferenceDoc.docx
---

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

df<-read.csv('Productdata.csv')
```

```{r loops, echo=F, results='asis'}
library(knitr)
for (i in 1:nrow(df))
{

print(kable(df[i,]))
}
```
Run Code Online (Sandbox Code Playgroud)

我真的不知道如何在我的 RMarkdown for WORD 中输入这样的图像。

eip*_*i10 6

这是一种使用 的方法kable,以及处理kableExtra某些格式的函数。到目前为止,我只能将其正确呈现为 html。如果我可以在 Word 中完成这项工作,我会更新。在下面的代码中,我使用了一些我碰巧躺在身边的图像。只需sprintf在原始ImageName列上运行相同的函数即可rmarkdown为您的图像获取适当的标记。

---
output:
  html_document:
    df_print: paged
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
library(knitr)
library(kableExtra)
library(tidyverse)

#df<-read.csv('Productdata.csv')
df<-data.frame(Amount= c('$25', '$45', '$75'), 
               Rate = c('1%', '1%', '3%'), 
               Location = c('Germany', 'Switzerland', 'England'),
               ImageName= c('GE.png', 'BE.png', 'CE.png'),
               Status = c('Sold','Unsold','Sold')
               )

# Change to names of my local images
df$ImageName =c("mal2.jpg",
                "serenity2.jpg",
                "blue_sun2.jpg")

# Add appropriate rmarkdown tagging
df$ImageName = sprintf("![](%s)", df$ImageName)
```

```{r loops, echo=F, results="asis"}
for (i in 1:nrow(df)) {

  # Select desired row
  d = df[i, ]

  # Change name of ImageName column to Status value
  names(d)[grep("ImageName", names(d))] = as.character(d[["Status"]])

  # Convert data to "long" format
  d = d %>% 
    select(-Status) %>% 
    gather(Product, value, Amount:Location) %>% 
    rename(` ` = value)

  # Render table using kableExtra for formatting
  print(kable(d, format="html") %>% 
          kable_styling(full_width=FALSE) %>% 
          collapse_rows(columns=1, valign="top"))
}
```
Run Code Online (Sandbox Code Playgroud)

这是 html 输出文件的样子:

在此处输入图片说明