gvisGeoMap +有光泽+代表

时间:2014-06-25 16:10:32

标签: r rstudio shiny googlevis

我尝试使用新的R演示+闪亮+ gvisGeoMap创建交互式幻灯片

这就是我现在所拥有的:

---
title: "Untitled"
author: "Name1"
date: "06/25/2014"
output: ioslides_presentation
runtime: shiny
---


## Slide with Interactive Plot

```{r, echo=FALSE}
suppressPackageStartupMessages(require(googleVis))
inputPanel(
  selectInput("select", 
        label = "Select G1 or G2",
        choices = list("G1", "G2"),
        selected = "G1")
)

renderPlot({
  if(input$select=="G1"){
    G1 <- gvisGeoMap(Exports, locationvar='Country', numvar='Profit',
                 options=list(dataMode="regions")) 

    plot(G1)
  }else{
    G2 <- gvisGeoMap(CityPopularity, locationvar='City', numvar='Popularity',
                 options=list(region='US', height=350, 
                              dataMode='markers',
                              colors='[0xFF8747, 0xFFB581, 0xc06000]')) 
    plot(G2)
  }

})
```

我可以创建html但地图不会打印。

1 个答案:

答案 0 :(得分:2)

googleVis图使用renderGvis函数。您需要传递googleVis对象,而不是调用plot。 需要将renderGvis分配给输出并使用htmlOutput

进行调用
---
title: "Untitled"
author: "Name1"
date: "06/25/2014"
output: ioslides_presentation
runtime: shiny
---


## Slide with Interactive Plot

```{r, echo=FALSE}
suppressPackageStartupMessages(require(googleVis))
inputPanel(
  selectInput("select", 
        label = "Select G1 or G2",
        choices = list("G1", "G2"),
        selected = "G1")
)

output$test <- renderGvis({
  if(input$select=="G1"){
    G1 <- gvisGeoMap(Exports, locationvar='Country', numvar='Profit',
                 options=list(dataMode="regions", width="100%")
                 , chartid = 'mychart') 

    G1
  }else{
    G2 <- gvisGeoMap(CityPopularity, locationvar='City', numvar='Popularity',
                 options=list(region='US', height=350, width="100%", 
                              dataMode='markers',
                              colors='[0xFF8747, 0xFFB581, 0xc06000]'
                              ), chartid = 'mychart') 
    G2
  }

})
htmlOutput("test")

```

enter image description here enter image description here