R Markdown 中的 2 列报告 - 将 HTML 呈现在数据框旁边 [英] 2 Column Report in R Markdown - Render HTML aside Data Frame
问题描述
我希望仅使用 R 和 Markdown 将 2 列报告呈现为独立的 HTML 文件.我对 R 中的降价非常陌生,所以我需要一些布局方面的帮助.
I am looking to render a 2 column report as a stand-alone HTML file using R and Markdown only. I am very new to markdown within R, so I need some help with the layout.
下图显示了我想使用 RMarkdown 呈现的布局.
The image below displays the layout of what I would like to render using RMarkdown.
左侧是 HTML,右侧是一些数据.
The HTML is on the left hand side and some data along the right hand side.
可以在此处找到 原始 HTML 和示例数据框:
注意:我使用 pander
包使用以下命令创建表:
Note: I used the pander
package to create the table using the following command:
pandoc.table(df, style="rmarkdown")
推荐答案
虽然这不是一个完美的解决方案,但它是一个入门的地方:益辉最近在 knitr 中添加了 HTML 模板,docco 是一个示例两栏页面: http://cran.r-project.org/web/packages/knitr/vignettes/docco-classic.html .
Although this is not a perfect solution, it is a place to get started: Yihui recently added HTML templates to knitr, and docco is a example two-column page: http://cran.r-project.org/web/packages/knitr/vignettes/docco-classic.html .
您可以在此处查看用于该输出的模板文件:https://github.com/yihui/knitr/blob/master/inst/misc/docco-template.html.
You can see the template file used for that output here: https://github.com/yihui/knitr/blob/master/inst/misc/docco-template.html.
或者,您可以尝试将内联 HTML 直接放在 R Markdown 块中,但这非常糟糕,您可能会觉得这样做是个坏人.我们使用 results='asis'
以便正确呈现 cat
ed HTML,并使用 out.extra=''
确保 HTML用于生成图形是立即生成的,而不是用于图像包含的 Markdown 语言.
Alternatively, you can try placing inline HTML right in your R Markdown chunks, but this is terribly hacky and you might feel like a bad person for doing it. We use results='asis'
so that the cat
ed HTML is rendered properly, and out.extra=''
to ensure that the HTML used to generate the figures is generated right away, rather than the Markdown language for image inclusion.
```{r two-column, results='asis', echo=FALSE, out.extra=''}
library(knitr)
cat("<table class='container'><tr>")
cat("<td>")
plot( rnorm(10) )
cat("</td>")
cat("<td>")
kable( rnorm(10), format="html" )
cat("</td>")
cat("</tr></table>")
```
在其上调用 knit
应该会为该特定块生成一个 2 列布局(尽管表格没有任何漂亮的样式;您可以使用一些 CSS 将其添加到自己中)
Calling knit
on that should produce a 2 column layout for that particular chunk (although without any nice styling for the table; you might add that in yourself with some CSS)
这篇关于R Markdown 中的 2 列报告 - 将 HTML 呈现在数据框旁边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!