gpt4 book ai didi

r - 如何在 RMarkdown 文档中排列 HTML 小部件(PDF、HTML)

转载 作者:行者123 更新时间:2023-12-04 14:40:59 25 4
gpt4 key购买 nike

我在 R notebook 工作并想用它来创建两个输出:一个 HTML 文档和 PDF 文档。

我的分析包括传单 map (html 小部件),即 将笔记本编织为 PDF 文档时出现问题 .感谢 webshot 函数现在包含在 knitr 中包,“knitr 将尝试使用 webshot 包自动为 HTML 小部件生成静态屏幕截图”( https://github.com/yihui/knitr/blob/master/NEWS.md )。

当我的输出是一系列相互堆叠的传单 map 时,这很好用,但我想以更简洁的行排列将 map 组合在一起(见下图)。

screenshot

这是我的 R 笔记本的可重现示例:gist

不幸的是,当我尝试将其编织到 PDF 文档时,我收到以下错误消息:

Error: Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:

always_allow_html: yes

Note however that the HTML output will not be visible in non-HTML formats.

如何在 PDF 文档中获得这种单行排列?

最佳答案

如果我理解正确,那么您所要做的就是添加一些块选项。这里的关键是选项 fig.show='hold'这决定了块中的所有图将被收集并一起显示在块的最后。

---
title: "R Notebook"
output:
pdf_document:
keep_tex: yes
html_notebook: default
---

###Default Arrangement
```{r, echo=FALSE,message=FALSE, fig.height=4, fig.width=2, fig.show='hold'}
#devtools::install_github("wch/webshot")

library(leaflet)
library(htmltools)
library(RColorBrewer)

m1 <- leaflet(quakes) %>%
addTiles() %>%
addMarkers(lng=174.768, lat=-36.852)

m2 <- leaflet(quakes) %>%
addProviderTiles("Esri.WorldGrayCanvas") %>%
addMarkers(lng=174.768, lat=-36.852)

m3 <- leaflet(quakes) %>%
addProviderTiles("Stamen.Toner") %>%
addMarkers(lng=174.768, lat=-36.852)
m1
m2
m3
```

如果您想同时为 pdf 和 html 输出使用这种格式,您可以将此脚本添加到您的 Rmd 文档的正文中(不在块内):
<script>
$(document).ready(function() {
$('.leaflet').css('float','left');
});
</script>

尝试通过块选项 out.extra 添加此 CSS 片段不起作用,因为 LaTeX 不知道如何处理 CSS。尽管在编译为 pdf 时忽略了 JS 代码。

enter image description here

关于r - 如何在 RMarkdown 文档中排列 HTML 小部件(PDF、HTML),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39562947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com