R Markdown - SparkTables 不呈现
R Markdown - SparkTables not rendering
我正在尝试使用 Rmarkdown 渲染火花table。但输出总是以原始 html 或 tex 格式出现。这取决于我渲染的是 PDF 还是 HTML。不确定在这里做什么?
library(sparkTable)
data("AT_Soccer")
content <- list(
function(x) {sum(x)},
function(x) {round(sum(x),2)},
function(x) {round(sum(x), 2)},
newSparkLine(lineWidth = 2,pointWidth = 6),
newSparkBar()
)
names(content) <- c("Points","ShotGoal","GetGoal","GoalDiff","winLose")
vars <- c("points","shotgoal","getgoal","goaldiff","wl")
stab <- newSparkTable(AT_Soccer,content,vars)
export(stab, outputType = "html") ### For HTML R-Markdown files
export(stab, outputType = "tex") #### For PDF R-Markdown files
我的输出(对于 html 个文件)如下所示:
pdf 输出为:
我正在尝试获得真正的火花table。我已经能够像这样渲染实际的 table:
showSparkTable(stab)
但是,这会在 Shiny 框架内打开火花 table。我正在尝试使用 spark tables 生成多个 rmarkdown 文档。
这个例子来自:https://journal.r-project.org/archive/2015-1/templ-kowarik-meindl.pdf。第 29 页。
HTML
的解决方案
这个设置对我有用。感谢马丁。尽管如此,仍然停留在 pdf 版本上。
knitr::opts_chunk$set(results = 'asis')
在稍微研究了文档之后,我总结了我学到的关于将 sparkTables 包含在 Rmd 文档中的知识:
1.对于 HTML 个文档 (outputType = 'html'
):
正如我所说,使用块选项 results = 'asis'
。
2。对于 PDF 文档 (outputType = 'tex'
):
对于 PDF 文档,您还需要上述选项。 但是 如果你不使用它,你会看到由 export()
生成的纯 LaTeX。
在该输出的最底部,您会发现一个重要提示:
## Information: please do not forget to add the following command before \begin{document} in your tex-fi
##
## \newcommand{\graph}[3]{ \raisebox{-#1mm}{\includegraphics[height=#2em]{#3}}}
所以我们要做的就是
- 在我们的序言中包含那行 LateX,
- 将
results = 'asis'
添加到代码块,
- 并将
export()
的参数infonote
设置为FALSE
。
最后一点防止了 LaTeX 编译器抛出的另一个错误(即我们已经定义了命令 \graph
)。
以下是 PDF 文档的工作示例:
---
title: "Plotting Plots Under Code"
author: "Martin"
date: "February 1, 2017"
output: pdf_document
header-includes:
- \newcommand{\graph}[3]{ \raisebox{-#1mm}{\includegraphics[height=#2em]{#3}}}
---
```{r setup, echo = F, warning = F, message = F, results = 'asis'}
library(sparkTable)
data('AT_Soccer')
content <- list(
function(x) {sum(x)},
function(x) {round(sum(x), 2)},
function(x) {round(sum(x), 2)},
newSparkLine(lineWidth = 2, pointWidth = 6),
newSparkBar()
)
names(content) <- c('Points', 'ShotGoal', 'GetGoal', 'GoalDiff', 'winLose')
vars <- c('points', 'shotgoal', 'getgoal', 'goaldiff', 'wl')
stab <- newSparkTable(AT_Soccer, content, vars)
export(stab, outputType = 'tex', infonote = F)
```
我正在尝试使用 Rmarkdown 渲染火花table。但输出总是以原始 html 或 tex 格式出现。这取决于我渲染的是 PDF 还是 HTML。不确定在这里做什么?
library(sparkTable)
data("AT_Soccer")
content <- list(
function(x) {sum(x)},
function(x) {round(sum(x),2)},
function(x) {round(sum(x), 2)},
newSparkLine(lineWidth = 2,pointWidth = 6),
newSparkBar()
)
names(content) <- c("Points","ShotGoal","GetGoal","GoalDiff","winLose")
vars <- c("points","shotgoal","getgoal","goaldiff","wl")
stab <- newSparkTable(AT_Soccer,content,vars)
export(stab, outputType = "html") ### For HTML R-Markdown files
export(stab, outputType = "tex") #### For PDF R-Markdown files
我的输出(对于 html 个文件)如下所示:
pdf 输出为:
我正在尝试获得真正的火花table。我已经能够像这样渲染实际的 table:
showSparkTable(stab)
但是,这会在 Shiny 框架内打开火花 table。我正在尝试使用 spark tables 生成多个 rmarkdown 文档。
这个例子来自:https://journal.r-project.org/archive/2015-1/templ-kowarik-meindl.pdf。第 29 页。
HTML
的解决方案这个设置对我有用。感谢马丁。尽管如此,仍然停留在 pdf 版本上。
knitr::opts_chunk$set(results = 'asis')
在稍微研究了文档之后,我总结了我学到的关于将 sparkTables 包含在 Rmd 文档中的知识:
1.对于 HTML 个文档 (outputType = 'html'
):
正如我所说,使用块选项 results = 'asis'
。
2。对于 PDF 文档 (outputType = 'tex'
):
对于 PDF 文档,您还需要上述选项。 但是 如果你不使用它,你会看到由 export()
生成的纯 LaTeX。
在该输出的最底部,您会发现一个重要提示:
## Information: please do not forget to add the following command before \begin{document} in your tex-fi
##
## \newcommand{\graph}[3]{ \raisebox{-#1mm}{\includegraphics[height=#2em]{#3}}}
所以我们要做的就是
- 在我们的序言中包含那行 LateX,
- 将
results = 'asis'
添加到代码块, - 并将
export()
的参数infonote
设置为FALSE
。
最后一点防止了 LaTeX 编译器抛出的另一个错误(即我们已经定义了命令 \graph
)。
以下是 PDF 文档的工作示例:
---
title: "Plotting Plots Under Code"
author: "Martin"
date: "February 1, 2017"
output: pdf_document
header-includes:
- \newcommand{\graph}[3]{ \raisebox{-#1mm}{\includegraphics[height=#2em]{#3}}}
---
```{r setup, echo = F, warning = F, message = F, results = 'asis'}
library(sparkTable)
data('AT_Soccer')
content <- list(
function(x) {sum(x)},
function(x) {round(sum(x), 2)},
function(x) {round(sum(x), 2)},
newSparkLine(lineWidth = 2, pointWidth = 6),
newSparkBar()
)
names(content) <- c('Points', 'ShotGoal', 'GetGoal', 'GoalDiff', 'winLose')
vars <- c('points', 'shotgoal', 'getgoal', 'goaldiff', 'wl')
stab <- newSparkTable(AT_Soccer, content, vars)
export(stab, outputType = 'tex', infonote = F)
```