【发布时间】:2013-07-10 20:35:36
【问题描述】:
使用 R,我希望能够在 github 的存储库中呈现包含 googleVis 图表的 .html 或 .md 文件(通过 knitr 或其他方式创建)。
我在运行?plot.gvis 时尝试关注帮助文件,我尝试将gvisData.js 和gvisFunctions.js 文件推入repo 并更改html 以引用这些文件,但我有一种感觉,我没有正确的 baseURL 以使 github 能够正确呈现它。
有没有人有一个简单的 URL 示例,该 URL 引用了呈现 googleVis 图表的 Github?
我尝试过使用这个http://lamages.blogspot.co.uk/2013/07/googlevis-tutorial-at-user2013.html,但没有看到它如何与 github 一起使用...
所以使用?plot.gvis 中给出的示例,这就是我尝试过的
myChartID <- "mtnc"
baseURL <- "https://raw.github.com/USER/REPO"
wwwdir <- getwd() ## the working directory is the local directory of the repo
## Create a motion chart
M <- gvisMotionChart(Fruits, "Fruit", "Year", chartid=myChartID)
## Write the data and functions into separate files:
cat(M$html$chart['jsData'], file=file.path(wwwdir, "gvisData.js"))
cat(M$html$chart[c('jsDrawChart', 'jsDisplayChart', 'jsChart')],
file=file.path(wwwdir, "gvisFunctions.js"))
## Create a html page with reference to the above
## JavaScript files
html <- sprintf('
<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi">
</script>
<script type="text/javascript" src="%s/gvisFunctions.js"></script>
<script type="text/javascript" src="%s/gvisData.js"></script>
<script type="text/javascript">
displayChart%s()
</script>
</head>
<body>
<div id="%s" style="width: 600px; height: 500px;"></div>
</body>
</html>
', baseURL, baseURL, myChartID, myChartID)
## Write html scaffold into a file
cat(html, file=file.path(wwwdir, paste("Chart", myChartID, ".html", sep="")))
### from this point I push up to the repo the following files
### gvisData.js, gvsiFunctions.js and Chartmtnc.html
## Display the result via
URL <- paste(baseURL,"/Chart", myChartID, ".html", sep="")
browseURL(URL)
任何建议都会很有用...
【问题讨论】:
标签: javascript r github knitr googlevis