是否可以使用垂直滚动条在 R markdown 中显示多个图像

H Y*_*ong 3 html r image scrollbar r-markdown

我正在尝试在 R Markdown 中创建一个报告(带有 html 输出),该报告使用垂直滚动条嵌入多个大脑 MRI 图像。最终目标是能够使用滚动条从上到下浏览大脑图像,反之亦然。我看过以下帖子:如何在滚动条中水平显示图像?但我不确定如何在 R markdown 中使用此代码。我对编码很陌生,所以不确定我的问题有多困难。

我正在使用函数 knitr::include_graphics 在 knit 到 HTML 时显示我的图像,我想知道应该添加什么来垂直滚动这些图像。

报告中使用 3 个图像的示例如下:

```{r echo=FALSE, out.width='100%', fig.align="center"}
library(knitr)
knitr::include_graphics('1.jpg')
knitr::include_graphics('2.jpg')
knitr::include_graphics('3.jpg')
```
Run Code Online (Sandbox Code Playgroud)

我应该在 R markdown 中的这个块中添加什么,以允许这些图像的垂直滚动?感谢任何帮助,因为我之前描述的链接超出了我的理解水平。

谢谢。

Mau*_*ers 5

以下应该可以工作,但需要您手动设置框的宽度和高度。

# Put this in your css (without the style tags), or at the top of your Rmd document 
<style>
.vscroll-plot {
    width: 1000px;
    height: 200px;
    overflow-y: scroll;
    overflow-x: hidden;
}
</style>

# In your Rmd document wrap your code chunk in div tags with class vscroll-plot
<div class="vscroll-plot">
```{r pressure, echo=FALSE}
plot(mtcars$hp, mtcars$drat);
plot(mtcars$disp, mtcars$qsec);
```
</div>
Run Code Online (Sandbox Code Playgroud)

如果绘图超过指定高度,这将为您提供带有垂直滚动条的两个绘图。