jeffrey
jeffrey

Reputation: 3354

Is it possible to download googleVis plots from R?

Follow up from :

https://groups.google.com/forum/#!topic/shiny-discuss/u7gwXc8_vyY

I have the exact same R Shiny structured program as the user in the post, except I am using the googleVis Shiny package for my plots. For example, here is a plot of a gVis table:

 output$gvisTable <- renderGvis( {
    if (is.null(dataset))
      return(NULL)


    gvisTable(dataset)



  })

EDIT:

My code to save ggplots:

server.R
    name <- paste0(input$filename, ".png")
        print(p)
        if(input$savePlot) {
          ggsave(name, p, type="cairo-png")
        }

ui.R (in sidePanel)

wellPanel(
                       textInput('filename', "Filename"),
                       checkboxInput('savePlot', "Check to save")  
                     )

This is what I am using to try to save gVis plots:

name <- paste0(input$filename, ".png")
    if(input$savePlot) {
      png(name, *INPUT GVIS PLOT HERE*, type="cairo-png")
      dev.off()
    }

This does not work: I get the error: 'non-numeric argument to binary operator'

I can't find a way to allow the user to download a gVis plot. I can't use the method in the linked post because you cannot 'print' a gVis plot.

Also, the files are locally saved to my R working directory, but I plan to upload this app to the web. Where would the files be saved for the user? Ideas?

Upvotes: 3

Views: 1689

Answers (1)

IRTFM
IRTFM

Reputation: 263362

I see no png method documented for gvis objects.

There are two ways to "print" documented in the help page linked from the googleVis main Index page for print.gvis. The default method (when the tag is NULL or "html") is to send a Java script page to your browser. The other (when you set tag="chart" is to construct an html file with the name you give it. I suppose you could arrange something with system commands sent to a running instance of a particular browser, but for that you should use different SO tags so that you attract the interest of people using the same software as you. (I'm using a Mac with Firefox and having no difficulties seeing the "printed" output.) If you plan to "upload it to the web", then you need to have a server. Is my impression this is a bit new for you correct?

print(GTM, tag="chart", file="test.html")  
#created in my working directory

Upvotes: 3

Related Questions