r-如何让webshot使用bookdown



我正在使用bookdown创建一个";书";,PDF和HTML格式。

在我有HTML视频的地方,当我渲染时会收到以下消息:

错误:在以latex输出为目标的文档中找到了生成HTML输出的函数。请将此文档的输出类型更改为HTML。或者,您可以允许通过将此选项添加到您的rmarkdown文件:

always_allow_html:真正的

但是请注意,HTML输出在非HTML格式中是不可见的。

依慧似乎不鼓励遵循关于always_allow_html的这些说明(https://github.com/rstudio/bookdown/issues/440):

您不应该向YAML添加always_allow_html:yes。

因此,搜索会产生一个解决方案(例如。https://bookdown.org/yihui/bookdown/html-widgets.html):

自knitr v1.13以来,HTML小部件将自动呈现为通过网络截图包拍摄的屏幕截图(Chang 2019(。当然,您需要安装webshot软件包。此外,您必须安装PhantomJS(http://phantomjs.org),因为它是webshot用来捕捉屏幕截图的。webshot和PhantomJS都可以从R:自动安装

。。。以及一些指示,我已遵照执行。

所以现在,我已经按照这些说明下载并安装了webshotphantomjs,这很容易得到确认:

> 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

所以。。。如果webshotphantomjs似乎已安装。。。我做错了什么?

感谢指导。。。

第页。

> 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

添加webshot库解决了我的问题。例如:

{r}
library(webshot)
DT::datatable(iris)

有趣的是,我在阅读了你的参考资料后尝试了这个解决方案。它就像一种魅力。谢谢你。

相关内容

最新更新