Javascript R github呈现js文件以查看googleVis html
使用R,我希望能够在github的repo中呈现一个Javascript R github呈现js文件以查看googleVis html,javascript,r,github,knitr,googlevis,Javascript,R,Github,Knitr,Googlevis,使用R,我希望能够在github的repo中呈现一个.html或.md文件(该文件通过knitr或其他方式创建),其中包含googleVis图表 在运行?plot.gvis时,我试图遵循帮助文件,并尝试将gvisData.js和gvisFunctions.js文件推到repo中,并更改html以引用这些文件,但是我有一种感觉,我没有正确的baseURL,以便github能够正确地呈现它 有没有人有一个简单的URL示例,它引用Github来呈现googleVis图表 我尝试过使用这个,但没有看到它
.html
或.md
文件(该文件通过knitr
或其他方式创建),其中包含googleVis
图表
在运行?plot.gvis
时,我试图遵循帮助文件,并尝试将gvisData.js
和gvisFunctions.js
文件推到repo中,并更改html以引用这些文件,但是我有一种感觉,我没有正确的baseURL,以便github能够正确地呈现它
有没有人有一个简单的URL示例,它引用Github来呈现googleVis图表
我尝试过使用这个,但没有看到它如何与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)
myChartID您不必要地使它复杂化了。当您试图在knitr
文档中使用googleVis
图表时,只需做一件事,即设置
options(gvis.plot.tag = 'chart')
您可以看到一个已发布的示例,并且可以找到源文件您不必要地使其复杂化了。当您试图在knitr
文档中使用googleVis
图表时,只需做一件事,即设置
options(gvis.plot.tag = 'chart')
您可以看到一个已发布的示例,并且可以找到源文件非常简单,谢谢!刚刚注意到你是slidify的作者!好的包装,做得好!非常简单谢谢!刚刚注意到你是slidify的作者!好的包装,做得好!