【发布时间】:2020-07-15 07:18:40
【问题描述】:
我正在使用bookdown 创建一个 PDF 和 HTML 格式的“书”。
在我有 HTML 视频的地方,我在渲染时收到此消息:
错误:在针对 Latex 输出的文档中找到产生 HTML 输出的函数。 请将此文档的输出类型更改为 HTML。或者,您可以允许 通过将此选项添加到 YAML 前端,以非 HTML 格式输出 HTML 你的 rmarkdown 文件:
always_allow_html: true
但是请注意,HTML 输出在非 HTML 格式中是不可见的。
易辉(https://github.com/rstudio/bookdown/issues/440)似乎不鼓励遵循这些关于always_allow_html的说明:
您不应将 always_allow_html: yes 添加到 YAML。
所以,搜索会产生一个解决方案(例如https://bookdown.org/yihui/bookdown/html-widgets.html):
自 knitr v1.13 起,HTML 小部件将自动呈现为通过 webshot 包截取的屏幕截图(Chang 2019)。当然,你需要安装 webshot 包。此外,您必须安装 PhantomJS (http://phantomjs.org),因为它是 webshot 用来捕获屏幕截图的工具。 webshot 和 PhantomJS 都可以从 R 自动安装:
...以及给出的一些指示,我已遵循。
所以现在,我按照这些说明下载并安装了webshot 和phantomjs,这很容易确认:
> webshot::is_phantomjs_installed()
[1] TRUE
> webshot:install_phantomjs()
It seems that the version of `phantomjs` installed is greater than or equal to the requested version.To install the requested version or downgrade to another version, use `force = TRUE`.
Error in webshot:install_phantomjs() : argument of length 0
无论我使用webshot:install_phantomjs() 还是webshot:install_phantomjs(force=TRUE),都没有任何变化。
确实,这失败了:
> webshot:install_phantomjs(version="2.1.1", force=TRUE)
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 637 100 637 0 0 0 1585 0 --:--:-- --:--:-- --:---:-- --:--:-- 1588
0 16.3M 100 16.3M 100 16.3M 0 0 3244k 0 0:00:05 0:00:05 --:--:-- 3926k
0:01 0:10:39 49930phantomjs has been installed to /Users/pdunn2/Library/Application Support/PhantomJS
Error in webshot:install_phantomjs(version = "2.1.1", force = TRUE) :
argument of length 0
所以...如果似乎安装了webshot 和phantomjs...我做错了什么?
感谢指导...
P.
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] webshot_0.5.2 bookdown_0.20
loaded via a namespace (and not attached):
[1] packrat_0.5.0 digest_0.6.25 jsonlite_1.7.0 magrittr_1.5 evaluate_0.14 rlang_0.4.7 stringi_1.4.6
[8] curl_4.3 rstudioapi_0.11 rmarkdown_2.3 webshot_0.5.2 tools_4.0.2 stringr_1.4.0 xfun_0.15
[15] yaml_2.2.1 rsconnect_0.8.16 compiler_4.0.2 askpass_1.1 htmltools_0.5.0 openssl_1.4.2 knitr_1.29
【问题讨论】:
-
一种选择是使用 if 语句将一个输出用于一种格式,另一个用于其他格式。对于类似的问题,我实现了类似 if latex output format, print(image).
-
谢谢马克。虽然这是可能的,但我更希望按照手册进行操作(并且它使用按描述工作)。我也可以使用
children方法。但这对我的文档来说是很多额外的工作,这不应该是必要的。所以显然有些事情出了问题......我真的更喜欢修复一些事情。有什么想法吗? -
您可以尝试通过 rstudio cloud 运行 - 这将确认它是否是特定于平台的。
-
我可以补充一点,它上周还在工作,平台没有改变。因此,截至上周,它确实可以在我的 Mac 上运行。我确实将 R 更新到了最新版本……但没有其他人报告任何问题……仍然感到困惑!