Search code examples
rgoogle-visualizationshinygooglevis

R Shiny: call to renderGvis() for google charts doesn't produce a chart


(Update: resolved height/width of div issue; changed question). I'm doing:

output$mainplot <- renderGvis({gvisBubbleChart()}, chartid="foo")

RESULT: blank plot. I tried the gvisBubbleChart() call separately and it does create the gvis object, as far as i can tell.

> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] googleVis_0.5.7  data.table_1.9.4 shiny_0.11      

loaded via a namespace (and not attached):
 [1] chron_2.3-45    digest_0.6.7    htmltools_0.2.6 httpuv_1.3.2    mime_0.2        plyr_1.8.1     
 [7] R6_2.0.1        Rcpp_0.11.3     reshape2_1.4.1  RJSONIO_1.3-0   stringr_0.6.2   tools_3.1.2    
[13] xtable_1.7-4   
> 

Solution

  • chartid="foo" needs to go inside the gvisBubbleChart() as examples given here

    rm(list = ls())
    library(googleVis)
    library(shiny)
    times <- seq(c(ISOdate(2014,01,06)), by = "day", length.out = 100)
    data1 <- round(runif(100, min = 100, max = 1000))
    test <- round(runif(100, min = -10, max = 10))
    my_data <- as.data.frame(cbind(as.character(times),data1,test))
    colnames(my_data) <- c("time","data1","test")
    
    ui =fluidPage(mainPanel(htmlOutput("view")))
    server = function(input, output, session){
      datasetInput <- reactive({
        gvisBubbleChart(my_data,idvar="test", 
                        xvar="time", yvar="data1", chartid="foo")})
      output$view <- renderGvis({datasetInput()})
    }
    runApp(list(ui = ui, server = server))