【问题标题】:renderGvis does not work in rmarkdownrenderGvis 在 rmarkdown 中不起作用
【发布时间】:2016-03-02 22:10:50
【问题描述】:

我尝试在 rmarkdown 页面中显示 googleVis 图表,但它不起作用...相反,它在浏览器中逐字显示 R 代码。

结果

function () 
{
    chart <- func()
    paste(chart$html$chart, collapse = "\n")
}
<environment: 0x5bd7558>

代码

```{r echo=F}
library(googleVis)

df <- data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32))

renderGvis({
  gvisColumnChart(df, xvar="country", yvar=c("val1", "val2"))
})

```

【问题讨论】:

    标签: r shiny r-markdown googlevis


    【解决方案1】:

    不知道你还有没有卡住,顺便回答一下,对别人有用吗。

    您的代码需要进行 2 处更改:

    • 添加op &lt;- options(gvis.plot.tag='chart')语句仅将HTML文件的图表组件写入输出文件check this
    • 添加results='asis' 声明以便返回原始 html check this

    因此,您的代码应该改为(.Rmd 文档):

    ---
    title: "testGoogleVis"
    output: html_document
    ---
    
    ```{r echo=F, results='asis'}
    library(googleVis)
    op <- options(gvis.plot.tag='chart')
    
    df <- data.frame(country=c("US", "GB", "BR"), val1=c(1,3,4), val2=c(23,12,32))
    
    plot(gvisColumnChart(df, xvar="country", yvar=c("val1", "val2")))
    ```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-30
      • 2023-01-29
      • 2019-12-10
      • 2016-02-28
      • 1970-01-01
      • 2018-12-17
      • 2019-08-13
      相关资源
      最近更新 更多