gpt4 book ai didi

在 rmarkdown Rmd 中渲染 google 图表的代码

转载 作者:行者123 更新时间:2023-12-02 17:34:02 25 4
gpt4 key购买 nike

Google 有一些漂亮的图表。我确信有很好的 R 包装器包可以做我想做的事情,但我想学习如何自己包含 google 图表,因为它可能比包含 google 图表的 R 包装器更灵活。

下面是一个 .Rmd,它具有一个 donut 函数来生成 the donut from Google chart gallery 。该函数输出如下所示的预期代码,但实际编织此代码会导致以下 pandoc 转换错误。如何在 Rmarkdown .Rmd 文件中正确包含 google 图表代码?

错误

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>

最佳答案

这听起来很像 bug the hs-tls library最近有,pandoc依赖哪个通过https下载图片等。

最有可能的是,使用更新的 pandoc nightly (或从源代码编译)并确保它使用 tls >= 1.3.9 将解决您的问题。

关于在 rmarkdown Rmd 中渲染 google 图表的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44136481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com