Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use googleCloudStorageR to automatically upload to Cloud Storage
---
title: "Host image files on Google Cloud storage"
author: "Michael Whitaker"
date: "January 12, 2017"
output:
html_document:
self_contained: false
---
```{r setup, include=FALSE}
library(knitr)
library(googleCloudStorageR)
opts_chunk$set(echo = TRUE)
opts_knit$set(upload.fun = function(file) {
upload_try <- gcs_upload(file, name = basename(file), predefinedAcl = "publicRead")
paste0("https://storage.googleapis.com/BUCKETNAME/",upload_try$name)
})
```
## R Markdown
The function in the above chunk uploads any generated images and adds the src URL automatically in the generated HTML file. Just change to your **BUCKETNAME**
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
plot(cars)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment