在闪亮的文档中显示ggvis图

时间:2014-07-05 17:08:27

标签: r shiny ggvis

ggvis是否与Shiny Documents合作?

在此示例中,ggplot可见,但ggvis不是

---
title: "testShiny"
runtime: shiny
output: html_document
---

ggplot2

```{r, echo=FALSE}

require(ggplot2)

renderPlot({
  ggplot(women, aes(height, weight))+
    geom_point()+
    theme_bw()

  })

```

ggvis

```{r, echo=FALSE}

require(ggvis)

renderPlot({
  women %>%
    ggvis(x= ~height, y = ~weight) %>%
    layer_points()

  })

```

在搜索时遇到了bind_shiny,但它没有解决问题

1 个答案:

答案 0 :(得分:3)

您需要使用bind_shiny为可视化分配ID。然后,您需要使用ggvisOutput在DOM中创建一个元素来显示可视化:

---
title: "testShiny"
runtime: shiny
output: html_document
---

```{r, echo=FALSE}

require(ggvis)
require(knitr)
require(shiny)

ggvisOutput("p")

women %>%
  ggvis(x= ~height, y = ~weight) %>%
  layer_points()%>%
  bind_shiny("p")

```

enter image description here