【问题标题】:R github rendering js files to see googleVis htmlR github 渲染js文件看googleVis html
【发布时间】:2013-07-10 20:35:36
【问题描述】:

使用 R,我希望能够在 github 的存储库中呈现包含 googleVis 图表的 .html.md 文件(通过 knitr 或其他方式创建)。

我在运行?plot.gvis 时尝试关注帮助文件,我尝试将gvisData.jsgvisFunctions.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


    【解决方案1】:

    你把它不必要地复杂化了。当您尝试在knitr 文档中使用googleVis 图表时,您只需要做一件事,即设置

    options(gvis.plot.tag = 'chart')
    

    你可以看到一个发布的例子here,源文件可以在here找到

    【讨论】:

    • 谢谢很简单!刚刚注意到你是 slidify 的作者!很棒的包裹做得很好!
    猜你喜欢
    • 2017-02-11
    • 2016-02-06
    • 2020-06-25
    • 1970-01-01
    • 2021-07-23
    • 2017-06-25
    • 2018-08-10
    • 1970-01-01
    • 2022-01-08
    相关资源
    最近更新 更多