r - 在 rmarkdown 中渲染 fusionchartsR htmlwidgets
问题描述
我正在构建一个名为fusionchartsR
(https://github.com/alexym1)的新 htmlwidget 包。我试图在我的 rmarkdown 报告中嵌入一小段代码,但是它不起作用,我不知道为什么。我尝试了不同的策略但没有任何成功。
第一个策略
---
title: "Stack overflow"
author: "John Doe"
date: "01/04/2020"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Render an htmlwidget graphic
```{r}
library(fusionchartsR)
df <- data.frame(label = c("Venezuela", "Saudi", "Canada", "Russia"), value = c(290, 260,180, 115))
fusionPlot(data = df, type = 'pie2d') %>%
fusionTheme(theme = "fusion")
```
第二种策略
# Webshot and phantomjs have been previously installed.
library(webshot)
webshot::install_phantomjs()
# Then, I loaded packages and built a little piece of code
library(fusionchartsR)
library(htmlwidgets)
df <- data.frame(label = c("Venezuela", "Saudi", "Canada", "Russia"), value = c(290, 260,180, 115))
widget <- fusionPlot(data = df, type = 'pie2d') %>%
fusionTheme(theme = "fusion")
# Save a rendered widget to an HTML file
saveWidget(widget = widget, file = "Mywidget.html")
# An error appeared: `Error: pandoc document conversion failed with error 99`
# Take a webshot
webshot(url = "Mywidget.html", file = "webshot.png")
Mywidget.html 可以在您的 Documents 文件夹中找到。
我怎么解决这个问题 ?我会很感激的!
解决方案
而不是使用 webshot,您应该考虑在https://github.com/rstudio/webshot2上尝试webshot2 ,它不会受到此问题的影响。我已经使用 webshot2 复制了您的场景,问题已解决,如下图所示。请参阅我对类似案例的详细回答。
编码:
# Webshot and phantomjs have been previously installed.
library(webshot2)
# install.packages("remotes")
# remotes::install_github("alexym1/fusionChartsR")
# Then, I loaded packages and built a little piece of code
library(fusionchartsR)
library(htmlwidgets)
df <- data.frame(label = c("Venezuela", "Saudi", "Canada", "Russia"), value = c(290, 260,180, 115))
widget <- fusionPlot(data = df, type = 'pie2d') %>%
fusionTheme(theme = "fusion")
# Save a rendered widget to an HTML file
saveWidget(widget = widget, file = "Mywidget.html")
# An error appeared: `Error: pandoc document conversion failed with error 99`
# Take a webshot
webshot(url = "Mywidget.html", file = "webshot.png")
推荐阅读
- c# - 限制到外部 API 的传出连接
- userscripts - 如何使用 Tampermonkey 为计时器/秒表添加开始和停止按钮
- go - 使用依赖注入测试包装函数
- angular - 使用 HTML 插值来更改 Angular2+ 中的 CSS 样式是不好的做法吗?
- excel - 将文件另存为 csv,不断出现为 .xlsx
- html - 为什么我们不能使用 CSS 自定义 HTML 中选择选项的突出显示颜色?
- c# - 使用自定义过滤器在表单中输入 HTML 时 ASP.NET MVC 处理错误
- perl - 将导入的函数传递给 Perl 中的另一个包
- python - 数据框:如何为每一行选择不同的列
- r - 如何解决 RSelenium 错误消息“无法连接到 localhost 端口 4444:连接被拒绝”?