Hi everyone - I have a shell script that automatically runs an R script who's output is several RMD files, a CSV, an HTML file, and a screenshot of the rendered HTML file.
The R script uses the webshot2 package to open the HTML file in a headless chromium browser and capture the rendered output. When I run the shell file from the terminal everything works fine - but when I run it through KM everything works except that the screenshot file never appears.
Is there some KM permission item that I am missing? I am having trouble figuring out why I am getting this behavior.
Edit: I am not getting any errors when this runs...just not the desired output.
Tricky to tell without seeing the macro, but 99% of the time an "it works in Terminal but not in a KM 'Execute Shell Script' action" is because the $PATH environment variable is not the same in each (unless you change it yourself).
Simple fix -- use explicit paths. Run which webshot2 in Terminal and use the output in place of webshot2 in your KM shell script.
If you are going to use the "Execute Shell Script" action you should read the Wiki page carefully, especially the bits about using KM variables and paths.
The Shell script only calls the R script and the paths are all read from the R environment, or explicitly stated in the R script. When executed by KM the R script has no issues with the path to anything else (other files, package dependencies, functions, etc...) it is only for the webshot2 command.
Here is what is in my shell script:
#! /bin/bash
cd /Users/Brandon/Documents/R_Projects/DingerStats/
/usr/local/bin/Rscript ~/Documents/R_Projects/DingerStats/run_simulations_script.R
Used the macro that @ccstone shared to determine terminal $PATH and KM $PATH. Spoiler: they are different.
I added PATH= to the top of my shell script.
Tested to see if the script worked running from terminal (it worked)
Tested to see if the script worked running from KM (it worked)
I assume the webshot2 package was not available via the KM path but the other packages were, hence the reason I was getting all outputs except for the image created by webshot.
all of my cd's are written in the R script (using R's setwd() function) not sure if that matters.
I am webshotting a local html file that the R script spits out - not a webpage.
I installed webshot via RStudio's package manager feature - are you using RStudio or another editor? I saw some forum posts with the same issue when folks tried to change from RStudio to vscode.