سؤال

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.

The image below displays the layout of what I would like to render using RMarkdown.

enter image description here

The HTML is on the left hand side and some data along the right hand side.

The raw HTML and the example dataframe can be found here:

Note: I used the pander package to create the table using the following command:

pandoc.table(df, style="rmarkdown")
هل كانت مفيدة؟

المحلول

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 .

You can see the template file used for that output here: https://github.com/yihui/knitr/blob/master/inst/misc/docco-template.html.

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 cated 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>")
```

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)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top