谷歌有一些漂亮的图表。我知道有一些不错的R包来做我想要的事情,但是我想学习如何自己包含谷歌图表,因为这样可能比包含谷歌图表的R包更加灵活。
下面是一个.Rmd文件,它包含一个donut
函数,用于生成Google图表库中的甜甜圈图表。该函数按预期输出代码,但实际上,在编织时会出现以下pandoc转换错误。在Rmarkdown .Rmd文件中如何正确地包括谷歌图表代码?
错误
output file: ttt.knit.md
pandoc.exe: Could not fetch https://www.gstatic.com/charts/loader.js
HttpExceptionRequest Request {
host = "www.gstatic.com"
port = 443
secure = True
requestHeaders = []
path = "/charts/loader.js"
queryString = ""
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
(InternalException (HandshakeFailed Error_EOF))
Error: pandoc document conversion failed with error 67
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS ttt.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output ttt.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\R\R-3.3.2\library\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "C:\Users\trinker\AppData\Local\Temp\RtmpWI5M7o\rmarkdown-str5910399322d6.html" --mathjax --variable "mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"' had status 67
Execution halted
Rmd MWE
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
donut <- function(){
out <- c("<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>",
"<script type=\"text/javascript\">", " google.charts.load(\"current\", {packages:[\"corechart\"]});",
" google.charts.setOnLoadCallback(drawChart);", " function drawChart() {",
"var data = google.visualization.arrayToDataTable([", " ['Task', 'Hours per Day'],",
" ['Work', 11],", " ['Eat', 2],", " ['Commute', 2],",
" ['Watch TV', 2],", " ['Sleep', 7]", "]);", "", "var options = {",
" title: 'My Daily Activities',", " pieHole: 0.4,", "};", "",
"var chart = new google.visualization.PieChart(document.getElementById('donutchart'));",
"chart.draw(data, options);", " }", "</script>", "", "<div id=\"donutchart\" style=\"width: 900px; height: 500px;\"></div>"
)
cat(paste(out, collapse = "\n"))
}
```
```{r results='asis'}
donut()
```
donut
输出而不使用rmarkdown编织
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
title: 'My Daily Activities',
pieHole: 0.4,
};
var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
chart.draw(data, options);
}
</script>
<div id="donutchart" style="width: 900px; height: 500px;"></div>
self_contained: no
,然后再进行编织...它会编织,但我必须在浏览器中打开 RStudio 窗格。 - Tyler Rinker(InternalException (HandshakeFailed Error_EOF))
在昨天发布的这个问题中也出现了:https://stackoverflow.com/questions/44120395/error-when-knitting-github-document-pandoc-document-conversion-failed-with-erro - scoa