Search code examples
rgoogle-visualizationgooglevisshinydashboardgvisgeomap

gvisGeoChart with shiny Dashboard


Unable to get output for givsGeoChart in my shiny Dashboard.

Below is the code for the same.

library(shiny)
library(shinydashboard)
library(googleVis)

ui <- dashboardPage(
       dashboardHeader(),
       dashboardSidebar(),
       dashboardBody(
          htmlOutput("Accidents")
                    )
                   )

server <- function(input, output) {

      output$Accidents <- renderGvis({
            gvisGeoChart(Dum, "States","Road_Accident",
            options=list(region="IN",displayMode="regions",resolution="provinces",width="100%"))
            })
          }

shinyApp(ui, server)

The above code doesn't work.

GeoStates_IN <- gvisGeoChart(Dum, "States","Road_Accident",options=list(region="IN",displayMode="regions",resolution="provinces",width="100%"))
plot(GeoStates_IN)

whereas this code works.Unable to figure out what is missing in above code.

Any kind of help is appreciated.


Solution

  • Problem has something to do with your options() or data. Is your variable dum cotaining columns "States" and "Road_Accident". Have you included the data in server.R?

    This works:

    library(shiny)
    library(shinydashboard)
    library(googleVis)
    
    ui <- dashboardPage(
           dashboardHeader(),
           dashboardSidebar(),
           dashboardBody(
              htmlOutput("Accidents")
                        )
                       )
    
    server <- function(input, output) {
    
          output$Accidents <- renderGvis({
                data(Exports)
                #map<-gvisGeoChart(Exports, "States","Road_Accident",
                #options=list(region="IN",displayMode="regions",resolution="provinces",width="100%"))
                map<-gvisGeoChart(Exports, locationvar='Country', colorvar='Profit',
                       options=list(projection="kavrayskiy-vii"))
                return(map)
                })
              }
    
    shinyApp(ui, server)