Google has great graphics. I am sure there are good R wrapper packages there to do what I want, but I want to learn how to enable the google diagram, as it will most likely be more flexible than the R shell to include the Google diagram.
Below is .Rmd, which has the function donutto create a donut from the Google chart gallery . The function outputs the code as expected below, but actually knit this result in the following pandoc conversion error. How to properly include Google chart code in an Rmarkdown file. Rmd?
Error
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 conclusion sans rmarkdown knitting
<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>