R github渲染js文件以查看googleVis html
R github rendering js files to see googleVis html
使用R,我希望能够在github中的repo中呈现包含googleVis
图表的.html
或.md
文件(通过knitr
或其他方式创建)。
在运行?plot.gvis
时,我试图遵循帮助文件,并尝试将gvisData.js
和gvisFunctions.js
文件推送到repo中,并更改html以引用这些文件,但我有一种感觉,我没有正确的baseURL,以便github能够正确地呈现它。
有没有人有一个简单的URL例子,它引用了Github来呈现googleVis图表?
我试过用这个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)
任何建议都是有用的。。。
您不必要地使它复杂化了。当您尝试在knitr
文档中使用googleVis
图表时,您只需要做一件事,即设置
options(gvis.plot.tag = 'chart')
您可以在这里看到一个已发布的示例,源文件可以在这里找到
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 如何设置html元素填充的动画
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 如何编写HTML输入的JS内联
- Dojo不解析自定义小部件的模板html中的小部件声明性
- 使用javascript将动态表从一个html页面打印到另一个html页
- 通过javascript重定向html传递php变量
- 如何使Javascript动态html表及其上的事件
- 在chrome.tabs.onCreated之后加载HTML页面
- 如何在vs2002中调试html页面
- 如何使用javascript或html下载PDF格式的填写表单
- 视频HTML没有'无法在Internet Explorer 11上工作
- HTML表单提交时未执行外部函数
- 如何将输入(type=text)从html表单传递到javascript函数
- 使用angular重定向到html页面
- 分析高度属性时出现意外值{{specs.height}}.index.html
- 在html Select中添加搜索
- 多级HTML表单
- R github渲染js文件以查看googleVis html