--- title: "Blàstula GenCat" author: "Xavier de Pedro Puente - CEB" date: "`r Sys.Date()`" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library("blastula") library("png") library("ggplot2") library("scales") library("ggExtra") library("gt") ``` ```{r} # Creo la clau d'enviament de correus (i en windows) una vegada només create_smtp_creds_key( id="foo_ceb", user = "foo@gencat.cat", provider = "office365", overwrite = FALSE ) # The system key store has been updated with the "blastula-v1-foo_ceb" key with the `id` value "foo_ceb". # * Use the `view_credential_keys()` function to see all available keys # * You can use this key within `smtp_send()` with `credentials = creds_key("foo_ceb")` ``` ```{r} # library library(ggplot2) library(ggExtra) # The mtcars dataset is proposed in R #head(mtcars) # classic plot : p <- ggplot(mtcars, aes(x=wt, y=mpg, color=cyl, size=cyl)) + geom_point() + theme(legend.position="none") # with marginal histogram p1 <- ggMarginal(p, type="histogram") my_ggplot <- blastula::add_ggplot( p1 , width=3, height = 3) ``` ```{r} my_image <- blastula::add_image(file = system.file("img", "Rlogo.png", package="png"), width = 50) ``` ```{r} my_table_gt <- starwars %>% select(-films) %>% head() %>% gt() %>% data_color( columns = birth_year, colors = scales::col_numeric(palette = "Blues", domain = range(0,800)) ) %>% as_raw_html() ``` ```{r} correu_alerta1 <- blastula::compose_email( body = md(glue::glue( "Benvolgut/da, acció requerida!: Gràfic: {my_ggplot} Imatge: {my_image} Taula heatmap: {my_table_gt} ")), footer = md(glue::glue("Correu enviat el {Sys.time()}.")) ) correu_alerta1 <- correu_alerta1 %>% add_attachment(file = system.file('img', 'pexels-photo-267151.jpeg',package='blastula') ) %>% # Imatge via adjunt add_attachment(file = system.file('examples', 'austin_home_sales.csv',package='blastula') ) %>% # CSV add_attachment(file = system.file('doc', 'DT.html',package='DT') ) %>%# html autocontingut add_attachment(file = system.file('legacy', 'examples', 'choropleth', 'Rplots.pdf',package='leaflet') ) # pdf ``` ```{r} # Previsualització correu_alerta1 ``` ```{r} correu_alerta1 |> blastula::smtp_send( to = "foo@bcn.cat", cc = "foo.ceb@gencat.cat", from = "foo.ceb@gencat.cat", subject = "Reviseu Canvis - Informe setmanal", credentials = creds_key("foo_ceb") ) ```