这并不完美。例如,我没有为屏幕大小添加处理程序,但我可以。不过,您需要让我知道您想要什么。
这使用了R Markdown中的Javascript。引擎是内置的。但是,我为您添加了代码以供检查(如果您选择):
names(knitr::knit_engines$get())
。
此外,在
setup
块中,我添加了
options(width = 75)
。这将影响所有块输出。您可以更改此设置以使其成为特定于块的选项。但是,默认值为80,因此您可能不会注意到任何区别。我之所以这样做是因为对于三个组中的两个,
Species
换行到了下一行。但是,对于
versicolor
来说,情况就不同了。这是统一性强制执行的一部分。
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
# confirm engine for 'js' (it was #37 for me)
names(knitr::knit_engines$get())
# set the output width for chunks' render
# this is to keep the summaries even (versicolor was doing its own thing)
options(width = 75)
library(tidyverse)
```
样式不是在一个块中。这个在设置和下一个块之间。
<style>
.setupCols {
display:flex;
flex-direction:row;
width: 100%;
}
.setupCols p{
display:flex;
flex-direction: column;
width: 45%;
}
.setupCols pre {
display:flex;
flex-direction: column;
width: 55%
}
.setupCols pre code {
font-size: 85%;
}
</style>
接下来是您的mapply
调用之前和之后的一些代码。
<div class="setupCols">
```{r graphOne}
mapply(FUN = function(.x) {
plot(.x)
summary(.x)
}, split(iris, iris$Species), SIMPLIFY = FALSE)
```
</div>
在这个块之后的任何时间点,您将添加一个样式块。如果您希望它应用多次,请将此块移动到最后。如果您只希望它应用于块(我命名为)
graphOne
,则将其设置为下一个块。
```{r styler,results='asis',engine='js'}
// search for class and tags
elem = document.querySelector('div.setupCols > pre > code');
// remove hashtags
elem.innerHTML = elem.innerHTML.replace(/#{2}/g, '');
// add newlines between summaries
elem.innerHTML = elem.innerHTML.replace(/\s{9}\n/g, '<br /><br />')
```
如果你在内联运行这个代码块,你将不会得到任何输出。但是,当你使用
knit
命令时,你将会看到这个输出。
我也添加了一些文本在这里,但这是它的样子:
![enter image description here](https://istack.dev59.com/JGciq.webp)
如果你想查看Javascript的运行情况,可以添加
eval = F
和
knit
。代码如下:
![enter image description here](https://istack.dev59.com/yaCjv.webp)
如果我漏掉了什么或者您有任何问题,请告诉我。