Skip to content

Commit

Permalink
fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
wleepang committed Jul 12, 2020
1 parent 9b811fb commit 2ddb93d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
9 changes: 4 additions & 5 deletions app/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dist\\R-Portable\\App\\R-Portable\\bin\\"

To use a system installed R set to something like:
"C:\\Program Files\\R\\R-3.3.2\\bin"
"C:\\Program Files\\R\\R-4.0.2\\bin"

command: <string>
Name of the specific R interpreter executable to use.
Expand All @@ -37,11 +37,9 @@

Defaults to:
"--vanilla"
*/
*/
"r_exec": {
"home": "C:\\Program Files\\R\\R-3.5.2\\bin",
"command": "Rscript.exe",
"options": "--vanilla"
"home": "C:\\Program Files\\R\\R-4.0.2\\bin"
},

/* options for error logging
Expand All @@ -52,6 +50,7 @@
Name of the log file to store errors. Default is "error.log".
*/
"logging": {
"use_userprofile": true,
"filename": "error.log"
}
}
4 changes: 4 additions & 0 deletions app/shiny/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ server = function(input, output, session) {
"iris" = iris)
})

output$commandArgs = renderPrint({
commandArgs()
})

output$dataSummary = renderPrint({
summary(dataset())
})
Expand Down
1 change: 1 addition & 0 deletions app/shiny/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ui = fluidPage(

mainPanel(
tags$div(sprintf("Global Variable Value: %s", GLOBAL_VAR)),
verbatimTextOutput("commandArgs"),
verbatimTextOutput("dataSummary"),
tableOutput("dataView")
)
Expand Down
25 changes: 19 additions & 6 deletions dist/script/wsf/js/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
var oFSO = WScript.CreateObject("Scripting.FileSystemObject");
var oShell = WScript.CreateObject("WScript.Shell");

var sBaseDir = oFSO.GetAbsolutePathName('.');
var fConfig = oFSO.OpenTextFile('app\\config.cfg', 1); // 1 = for reading
var sConfig = (fConfig.AtEndOfStream) ? "" : fConfig.ReadAll();

fConfig.Close()

if (this.JSON) {
var oConfig = (sConfig !== "") ? JSON.parse(JSON.minify(sConfig)) : undefined;
} else {
Expand Down Expand Up @@ -52,11 +55,12 @@ var oDEFAULTS = {
// If deployed to users individually, keep with the deployment (default)
// If deployed to a central location (e.g. a network share) use a directory in
// each user's %userprofile%
//' Determine User Home directory
var sUPath = oShell.ExpandEnvironmentStrings("%USERPROFILE%");
var sAppUPath = sUPath + "\\." + oConfig.appname;
var sLogPath = 'log';
if (oConfig.logging.use_userprofile) {
//' Determine User Home directory
var sUPath = oShell.ExpandEnvironmentStrings("%USERPROFILE%");
var sLogPath = sUPath + "\\." + oConfig.appname;
var sLogPath = sAppUPath;
}

//' Create an application log directory as needed
Expand All @@ -80,11 +84,20 @@ if (!oFSO.FileExists(Rexe)) {

function enquote(s) { return "\"" + s + "\""; }

var RScriptFile = "dist\\script\\R\\run.R";
var RScriptFile = sBaseDir + "\\dist\\script\\R\\run.R";
var Outfile = sLogPath + "\\" + sLogFile;

var strCommand = [enquote(Rexe), Ropts, enquote(RScriptFile), "1>", Outfile, "2>&1"].join(" ");
var strCommand = [enquote(Rexe), Ropts, enquote(RScriptFile), ">", enquote(Outfile), "2>&1"].join(" ");
var intWindowStyle = 0;

// Either .Run or Rscript inappropriately captures the redirection to the log file as a parameter
// As a workaround create a temporary .bat file to invoke strCommand as needed
var batFilePath = enquote(sAppUPath + '\\run.bat');
var batFile = oFSO.CreateTextFile(sAppUPath + '\\run.bat', 2); // 2 = for writing
batFile.WriteLine("cd " + enquote(sBaseDir));
batFile.WriteLine(strCommand);
batFile.Close();

/*
' other values:
' 0 Hide the window and activate another window.
Expand All @@ -103,4 +116,4 @@ var intWindowStyle = 0;
//' continue running script after launching R
var bWaitOnReturn = false;

oShell.Run(strCommand, intWindowStyle, bWaitOnReturn);
oShell.Run(batFilePath, intWindowStyle, bWaitOnReturn);

0 comments on commit 2ddb93d

Please sign in to comment.