Currently I'm saving the object in onedrive and then using export_formattable()
to paste in a powerpoint slide using Ph_with()
from officeR
. This method is taking a long time to execute. Is there a more efficient alternative?
library(formattable)
# Example table
col1 <- c(90, 4.2, 5.6, 7.1)
col2 <- c(5.0, 64, 10.3, 6.0)
col3 <- c(4.7, 6.3, 1.5, 70)
mydata = data.frame(col1, col2, col3)
Greenc = "#71ca97"
Redc="#ff7f7f"
yellowc="#FFC31A"
UpperCutoff = 80
LowerCutoff = 65
# define color_tile_mean function
color_tile_mean <- function (...) {
formatter("span", style = function(x) {style(display = "block",padding = "0 4px", `border-radius`
="4px", `background-color` = ifelse(x >UpperCutoff , Greenc,
ifelse(x<LowerCutoff,Redc,yellowc)))})}
# Formattable object
object = formattable(mydata, align=c(rep("c", NCOL(mydata))),list(area(col
=1:ncol(mydata))~color_tile_mean()))
# officeR codes to save object in a powerpoint body
mypres <- add_slide(mypres, layout = 'Title and Content', master = 'ABC Theme')
ph_with(mypres,value = external_img(Plot), location = ph_location_type(type = 'body'))