用于创建多列的 CSS 解决方案不允许控制分栏发生的位置。似乎会自动插入分栏符以在各列之间平均分配内容,这并不总是您想要的。
markdown 和 rmarkdown 中的“***”符号插入水平换行符,而不是新列。
除了用于幻灯片演示的 .Rmd 格式外,Rstudio 还提供了 .Rpres 幻灯片演示格式 (Rpresentations)。 Rpresentations 使用了一种略有不同的 markdown,其中“***”符号插入了一个新列。
以下是 RStudio 介绍 Rpresentations 的链接:
Two Column Layouts
Authoring R Presentations
以下是与您类似的 StackOverflow 问题的链接:
Two Column Layouts in RStudio
Two Column Layouts in markdown
Rpresentation 格式的最大缺点是它不支持用于交互式可视化的嵌入式闪亮应用程序。但 Rpresentation 确实支持交互式 webgl 图。下面是一个简单的例子。您可以将其保存到 .Rpres 文件中,在 RStudio 中打开它,然后将其编译为 HTML 幻灯片演示文稿。请注意最后一张幻灯片中的交互式 webgl 图,您可以使用鼠标进行操作。
Simple R Presentation
========================================================
title: "Simple R Presentation"
author: John Doe
date: `r format(Sys.time(), "%m/%d/%Y")`
width: 1900
height: 1000
```{r setup, include=FALSE}
# This is an R setup chunk, containing default options applied to all other chunks
library(knitr)
# This sets the chunk default options
opts_chunk$set(cache=TRUE, collapse=TRUE, error=FALSE, prompt=TRUE)
# This sets the chunk display theme
thm <- knit_theme$get("acid")
knit_theme$set(thm)
# This sets some display options
options(digits=3)
options(width=80)
```
My First Slide
========================================================
Hello World!
Creating Rpresentations isn't difficult at all!
<img src="https://community.filemaker.com/servlet/JiveServlet/showImage/2-180549-7694/staples-easy-button.png" width="500" height="500" />
***
The Cauchy-Schwarz Inequality:
$$
\left( \sum_{k=1}^n a_k b_k \right)^2
\leq
\left( \sum_{k=1}^n a_k^2 \right)
\left( \sum_{k=1}^n b_k^2 \right)
$$
Slide With R Code Chunk and Output in Two Columns
========================================================
First column contains simple R code that returns the summary of the cars data frame:
```{r, summ_cars, eval=FALSE, echo=TRUE, results="hold", size="tiny"}
summary(cars)
```
***
Second column contains the output of the code in the first column:
```{r, summ_cars, eval=TRUE, echo=FALSE, size="tiny"}
```
Slide With Plot
========================================================
First column with R code:
```{r, plot_cars, eval=TRUE, echo=(-(1:1)), fig.show="hide"}
par(cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5)
plot(cars)
```
***
Second column with plot:
```{r, plot_cars, eval=TRUE, echo=FALSE, fig.width=10, fig.height=8}
```
Slide with Interactive 3d Surface Plot
========================================================
First column with R code:
```{r, rgl_surf3d, eval=FALSE, echo=TRUE, webgl=TRUE, fig.show="hide"}
library(rgl) # load rgl
knit_hooks$set(webgl=hook_webgl)
# define function of two variables
foo <- function(x, y) y*sin(x)
# draw 3d surface plot of function
persp3d(x=foo, xlim=c(-5, 5), ylim=c(-5, 5), col="green", axes=FALSE)
```
***
Second column with plot:
```{r, rgl_surf3d, eval=TRUE, echo=FALSE, webgl=TRUE, fig.width=10, fig.height=8}
```