在rmarkdown中渲染fusionchartsR htmlwidgets

问题描述 投票:0回答:1

我正在构建一个名为fusionchartsRhttps://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。

我该如何解决这个问题?我将非常感激!

r r-markdown fusioncharts htmlwidgets
1个回答
0
投票

而不是使用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")

输出:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.