2

I have the following code that works fine. I would like to know if it's possible to take this and export it as a png file. Anyone know of an easy way to do this. I'm just getting started in the R world so a noob.

Here is my code

library(RODBC)
library(googleVis)

con <- odbcConnect("Live", uid="Rxyzuser", pwd="xxxxx")
attendees <- sqlQuery(con, "exec rpt_r_vis")

regCal <- gvisCalendar(attendees, 
                       datevar="Reg_add_date", 
                       numvar="Counts",
                       options=list(
                         title = "Registrations per Day Heatmap",
                         height = 400, width=1000,
                         calendar="{yearLabel: { fontName: 'Times-Roman',
                                    fontSize: 32, color: '#1A8663', bold:     true}, cellSize: 15,
                                    cellColor: { stroke: 'red', strokeOpacity: 0.2 },
                                    focusedCellColor: {stroke: 'red'}}")
  )
plot(regCal)


odbcCloseAll()
Sc-python-leaner
  • 259
  • 1
  • 2
  • 13

2 Answers2

1

I was looking into saving html files produced with googleVis as png myself and stumbled upon this thread here. I was able to solve my problem using webshot2::webshot().

i.e. you create an html file with googleVis and then use webshot2::webshot() to produce a png.

dat <- data.frame(From=c(rep("A",3), rep("B", 3)), 
                  To=c(rep(c("X", "Y", "Z"),2)), 
                  Weight=c(5,7,6,2,9,4))

sk1 <- googleVis::gvisSankey(dat, from="From", to="To", weight="Weight")

cat(sk1$html$chart, file = "Sankey.html") 

webshot2::webshot(url = "Sankey.html",
                  file = "Sankey.png",
                  vheight = 400,
                  vwidth = 430,
                  zoom = 5)
Patrick
  • 742
  • 7
  • 19
-3

did you try:

png("sample.png",width = 480, height = 480, units = "px")
plot(regCal)
dev.off()

Best,

Robert

  • Kind of works, I just get a white png file with nothing on it. Is there something else I need to do. I am getting the image created but there is nothing in the image file. – Sc-python-leaner Nov 05 '15 at 15:47
  • What happens if you do the following: plot(regCal); dev.copy(png,'filename.png') # creates .png in directory but nothing in it dev.off() # this inserts images, then keep calling it until reach "null device 1" – lawyeR Nov 06 '15 at 00:11