我正在使用这个rmd文件创建一个HTML文件。
并且。
输出结果没问题,但我需要 markdown 文件 (file.md) 以便稍后重新创建 html 文件(没有访问数据的情况下)。rmarkdown 生成了两个 md 文件 [file.knit.md] 和 [file.utf8.md],但是当我渲染其中任意一个时,htmlwidget 在 file.html 中丢失了。
我需要的是具有交互式htmlwidget的html文件,而不是该widget的png图像。使用以下代码,我可以生成一个file.md文件,然后渲染出一个带有widget png图像的html文件,而不是交互式js widget。
---
title: "test"
author: "me"
date: '`r Sys.Date()`'
output: html_document
---
```{r}
data(HairEyeColor)
rpivotTable::rpivotTable(data = HairEyeColor
, rows = "Hair"
,cols="Eye"
, vals = "Freq"
, aggregatorName = "Sum"
, rendererName = "Table"
, width="100%"
, height="400px")
```
并且。
rmarkdown::render( input = 'file.RMD' , output_file = 'file.html'
, output_format= html_document( self_contained=TRUE), clean = FALSE
, quiet = FALSE )
输出结果没问题,但我需要 markdown 文件 (file.md) 以便稍后重新创建 html 文件(没有访问数据的情况下)。rmarkdown 生成了两个 md 文件 [file.knit.md] 和 [file.utf8.md],但是当我渲染其中任意一个时,htmlwidget 在 file.html 中丢失了。
rmarkdown::render( input = 'file.utf8.md' , output_file = 'file.html'
, output_format= html_document( self_contained=TRUE) )
rmarkdown调用pandoc时有一个[--include-in-header]参数,指向一个包含小部件依赖项的临时文件,但我没有找到在渲染md文件时包含它的方法(即--include-in-header /tmp/Rtmp1M0RpP/rmarkdown-str1a169e14827.html")
下面是rmarkdown中的pandoc调用,但执行此命令仍会生成一个没有htmlwidget的html文件。
/usr/bin/pandoc +RTS -K512m -RTS file.utf8.md
--to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash
--output test._0021.html --smart --email-obfuscation none --self-contained --standalone
--section-divs --template /home/bergel/R/x86_64-pc-linux-gnu-library/3.3/rmarkdown/rmd/h/default.html
--variable 'theme:bootstrap' --include-in-header /tmp/RtmpqpGfD1/rmarkdown-str19b5232f45d7.html
--mathjax --variable 'mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
--no-highlight --variable highlightjs=/home/bergel/R/x86_64-pc-linux-gnu-library/3.3/rmarkdown/rmd/h/highlight
--variable navigationjs=/home/bergel/R/x86_64-pc-linux-gnu-library/3.3/rmarkdown/rmd/h/navigation-1.1
我需要的是具有交互式htmlwidget的html文件,而不是该widget的png图像。使用以下代码,我可以生成一个file.md文件,然后渲染出一个带有widget png图像的html文件,而不是交互式js widget。
rmarkdown::render( input = 'file.RMD' , output_file = 'file.md'
, output_format= md_document( ) )
我发现这个问题与这个问题有关: 提取包含htmlwidgets的.Rmd文件的html依赖项
x <- rmarkdown::render("file.RMD", run_pandoc = FALSE, clean = FALSE)
和attr(x, "knit_meta")
,你将得到一个包含所有必需依赖项的列表。我认为你可以创建一个函数,将所有这些添加到从.md
文件上的render
调用生成的 .html 文件中。 - Tutuchan