如何直接渲染到包含knit_expand的html rmd文件

时间:2019-02-18 20:16:42

标签: r r-markdown flexdashboard

我有两个Rmd文件

main.Rmd

---
title: "Report"
author: "User"
output:
    flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---


```{r setup, include=FALSE}
library(flexdashboard)
library(highcharter)
library(htmlwidgets)
library(lubridate)
library(knitr)
```


```{r run-numeric-md, include=FALSE}
warehouse <- data.frame("id" = c("WARE-01", "WARE-02", "WARE-03"))
warehouse$group <- c("1", "2", "3")
out = NULL
for (row in 1:nrow(warehouse))
    {
        out = c(out, knit_expand
            (
                'template.Rmd', 
                warehouse_id = warehouse[row, "id"],
                warehouse_group = warehouse[row, "group"]
            )
        )
    }
```


`r paste(knit(text = out), collapse = '\n')`

和模板。用于knit_expand命令的Rmd

Sales revenue net / {{warehouse_id}} {data-navmenu={{warehouse_group}}}
=====================================

Column {data-width=500}
-------------------------------------
### {data-height=100}

```{r}
valueBox("Sales revenue net",
         caption = paste("Item UPC:<b>", "</b> :: Contractor ID:<b>", "</b> :: Warehouse ID:<b>","{{warehouse_id}}" ,"</b>"))
```

### {data-height=900}



Column {data-width=500}
-------------------------------------

### {data-height=500}

### {data-height=500}

从菜单执行编织到flex_dashboard我能够产生所需的输出。但是我想从r脚本文件使用

执行main.rmd
rmarkdown::render(
    input = "main.Rmd", 
    output_file = "main.html",
    output_format = "all")

但是,当我执行r代码(如上)时,我会报错

  

do.call(output_format_func,options)中的错误:第二个参数   必须是列表

有什么想法我做错了吗?

1 个答案:

答案 0 :(得分:1)

使用output_format = "flex_dashboard"以及添加参数output_options=list(keep_md=T)可以生成html。

rmarkdown::render(
    input = "main.rmd", 
    output_file = "main.html",
    output_format = "all", output_options = list())

rmarkdown::render(
    input = "main.rmd", 
    output_file = "main.html",
    output_format = "flex_dashboard")