Search code examples
rdesktop-applicationshinyportable-applications

R Shiny as Windows Desktop App Creates Text File With Warning


I am a statistics student and I have created an app in R Shiny, went through all the steps described as per http://blog.analytixware.com/2014/03/packaging-your-shiny-app-as-windows.html and encounter the following issue: chrome portable does open, my app runs fine and I can use it, however a new file is created each time I press on vbs.run, it is named as some number i.e. 0.3928118 opening it in notepad yields the following:

proc.time() user system elapsed 3.55 0.26 9.48

However, in my code I do not use proc.time() function anywhere. When I try to delete the file - I cant do it unless I restart my pc. The error says : "The action can't be completed because the file is open in Google Chrome Portable". My run.vbs file looks like:

Randomize CreateObject("Wscript.Shell").Run "R-Portable\App\R-Portable\bin\R.exe CMD BATCH --vanilla --slave runShinyApp.R" & " " & RND & " ", 0, False

My runShinyApp.R looks like:

require(shiny,quietly = TRUE, warn.conflicts = FALSE) require(shinyjs,quietly = TRUE, warn.conflicts = FALSE) .libPaths("./R-Portable/App/R-Portable/library") browser.path = file.path(getwd(),"GoogleChromePortable/GoogleChromePortable.exe") options(browser = browser.path) shiny::runApp("./Shiny/",port=8888,launch.browser= TRUE,quiet=TRUE)

Note: I added lines 1 and 2 to runShinyApp.R because in that strange file I would also get Loading shiny...... note etc and this has removed them.

I would be very grateful if you could give me a hand with this as I have tried everything and spent weeks trying to make it work and I have no idea what is going wrong here...


Solution

  • This the relevant line in your VBScript code:

    CreateObject("Wscript.Shell").Run "R-Portable\App\R-Portable\bin\R.exe CMD BATCH --vanilla --slave runShinyApp.R" & " " & RND & " ", 0, False
    

    When you run R CMD BATCH foo.R it produces an foo.Rout file by default which contains the information that you have reproduced (https://stat.ethz.ch/R-manual/R-devel/library/utils/html/BATCH.html). You can test this by running R CMD BATCH on a simple R file.

    In your case, the name of the outfile is specified using the RND VBScript function, which is why you are getting the random name. AFAICT, there is no way to not generate an outfile, and as long as the R batch process is running (which is as long as the Shiny session lasts), the file is locked, so you cannot delete it. You might check whether Shiny still works if you replace R CMD BATCH with Rscript.

    Unless you are worried about your end-user being spooked by the appearance of strange files on their machine, it is harmless, and you should probably not worry about its existence. You can change your VBScript to name it more recognizably if you want.