gt::gtsave throws error 'Invalid path to Chrome' (save a .png via webshot)

1k Views Asked by At

I have an issue with some code that perfectly worked previously with my setup. I assume it fails now after webshot2 has superseded webshot. Anyway, I am not able to fix the following error.

Aim: I want to process data via teh gt package and save them through gt::gtsave() as a .png file.

Reprex:

library(tidyverse)
library(gt)
library(webshot)
library(webshot2)
 
 
df <- iris %>%
  slice(1:10)
 
table <- gt(df)
 
gtsave(table, paste("iris",".png",sep=""),expand=0,vwidth=350,vheight=240,zoom=3)

Everything works and is yielding a fine table until I attempt saving. I have searched the internet and found little help, yet tried some proposed fixes (more randomly, since they did not perfectly match my issue). Please note that I do have MS Edge installed (which worked fine previously) and nothing else was changed in regard of relevant hardware or software.

Error is the following:

Error trying to find path to Chrome
Error in initialize(...) : Invalid path to Chrome

Is it really due to the web shot not being able to recognize Edge installation or do I have to familiarize/customize my code to headless chrome (how?). Essentially, what can I do to make R/Rstudio recognize the Edge installation and save my .png?

1

There are 1 best solutions below

1
On

so we finally managed :) gt uses webshot2 and this un turn uses chromote. So, first, check if it finds the route chrome:

    chromote::find_chrome()

And if it doesn't find it, just assign it as:

    Sys.setenv(CHROMOTE_CHROME = "your route to/chrome.exe")

double-check with chromote::find_chrome() and you should see your route, and then it works.

In this same way, you can assign a different web browser

More info here and here.

Hope this helps!