Skip to content

Instantly share code, notes, and snippets.

@jrosell
Last active July 28, 2020 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrosell/2deee27bf64c58cacea1b7e46632a8fb to your computer and use it in GitHub Desktop.
Save jrosell/2deee27bf64c58cacea1b7e46632a8fb to your computer and use it in GitHub Desktop.
Código de ejemplo de generación de un PDF a partir de un board de Trello. En este caso https://trello.com/b/NoiWfLdi/trello-backend-example-public
---
title: "Trello to PDF"
author: "jrosell"
date: "2020-07-28"
output: pdf_document
---
## R Markdown
This is an R Markdown document. It gets Trello cards and its attachments from specific list on a public board and build a PDF document from it.
You can do it yourself by opening this file on RStudio and click the **Knit** button.
For this example, [$\text{\underline{this board}}$](https://trello.com/b/NoiWfLdi/trello-backend-example-public) is used.
## R code
```{r setup, results='hide',warning = FALSE, message = FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
if(!require(knitr)) install.packages("knitr")
if(!require(rmarkdown)) install.packages("rmarkdown")
if(!require(tidyverse)) install.packages("tidyverse")
library(jsonlite)
library(knitr)
library(rmarkdown)
trello_board_url <- "https://trello.com/b/NoiWfLdi/trello-backend-example"
json <- URLencode(paste(trello_board_url, ".json", sep = ""))
trello <- fromJSON(json)
cards <- trello$cards
attachments <- list()
for(i in seq_along(cards$attachments)){
if(length(cards$attachments[[i]])>0){
row <- list(
attachment_id = cards$attachments[[i]]$id,
attachment_url = cards$attachments[[i]]$url,
attachment_basename = basename(cards$attachments[[i]]$url)
)
attachments <- append(attachments, list(row))
}
}
attachments <- attachments %>% bind_rows(.id = 'id') %>% select(-id)
map2(.x = attachments$attachment_url,
.y = attachments$attachment_basename,
.f = ~download.file(.x, .y, mode="wb"))
```
# Published list
```{r cards, results='asis'}
output <- cards %>%
select(name, desc, idList, closed, url, idAttachmentCover) %>%
filter(idList == "5f2027680adc692cac5e2fe8", !closed) %>%
left_join(attachments, c("idAttachmentCover" = "attachment_id")) %>%
mutate(
markdown = paste('\n## ', name, '\n',
desc, '\n\n![', idAttachmentCover, '](', attachment_basename, ')\n\n', sep = ""),
) %>%
select(markdown) %>%
unlist()
cat(output)
```
@jrosell
Copy link
Author

jrosell commented Jul 28, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment