rgoogle-sheetsr-googlesheets

R script to insert images into Google Sheets


Is there a way to insert images, in this case ggplot2 charts, into a Google Sheet, using an R script? Maybe using the googlesheets package?

I see how to add an image to an Excel spreadsheet and I can add an image to a Google Sheet in my browser via Insert -> Image in the Sheets menus. But I'd like to add the image to my sheet from within an R script.


Solution

  • This is a bit of a hack, and it seems the image will take exactly the size of one cell by default. But it is a way to insert images:

    x <- gs_edit_cells(ss=x, ws="y", input='=IMAGE("https://i.sstatic.net/FrDZc.jpg")')
    

    You can then manually from within Google Sheets resize the cell and thus the image as well.

    Of course the new problem is now how to give an image a web-address from within R --- but I wouldn't think that is too hard.