I wrote an R App (with gWidgets) and it works fine in RStudio.
However, when I created bat file, it loads code just fine and it actually opens the first window of the app, but then the app closes and no error is thrown.
My batch file is simply:
<path where R is installed> <path where my program is saved>
Regarding my R code it is 99% of functions, however my last thing is not a function, but a code to open the welcome window (simplyfied):
First_window <- gwindow("Welcome")
g <- ggroup(horizontal = FALSE, container = First_window)
gtext("Welcome to Recovery Plan application", container = g, expand=TRUE)
gtext("Do you want to start a new project or open an old one?", container = g)
gbutton("New project", container=g, handler=function(h,...) foo_function)
What do I have to do?
I recommend you to add gtkMain()
at the end of script, it will cycle until destroy message would be sent.
Please see as below:
options("guiToolkit"="RGtk2")
library(RGtk2)
library(gWidgets)
library(gWidgetsRGtk2)
First_window <- gwindow("Welcome")
g <- ggroup(
horizontal = FALSE,
container = First_window)
gtext(
text = "Welcome to Recovery Plan application",
container = g,
expand=TRUE)
gtext(
text = "Do you want to start a new project or open an old one?",
container = g)
gbutton(
text = "New project",
container = g,
handler = function(h,...) gtkMainQuit)
gtkMain()
@echo off
"<path to R bin> \R.exe" CMD BATCH --no-save --no-restore "<path to R-file>\gtk.R"