我正在构建一个名为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")
可以在您的Documents文件夹中找到Mywidget.html。
我该如何解决这个问题?我将非常感激!
而不是使用webshot,您应该考虑在不受此问题困扰的https://github.com/rstudio/webshot2上尝试webshot2。我已经使用webshot2复制了您的方案,该问题已解决,如下图所示。参见my detailed answer至类似情况。
代码:
# 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")