/
run.R
57 lines (45 loc) · 1.61 KB
/
run.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# capture the current working directory
# set the package search path to the app specific library
# and the local R-portable site library
appwd = getwd()
applibpath = file.path(appwd, 'app', 'library')
.libPaths(c(applibpath, .Library))
message('library paths:\n', paste('... ', .libPaths(), sep='', collapse='\n'))
message('working path:\n', paste('...', appwd))
# get the application name from the config file
library(jsonlite)
config = fromJSON(file.path(appwd, 'app', 'config.cfg'))
# provide some initialization status updates to assure the user that something
# is happening
pb = winProgressBar(
title = sprintf('Starting %s ...', config$appname),
label = 'Initializing ...'
)
# wrap the startup process in tryCatch so that if any errors occur an appropriate
# error message can be displayed
appexit_msg = tryCatch({
packages = config$init_packages
message('loading packages: ', paste(packages, collapse = ', '))
for (i in seq_along(packages)) {
setWinProgressBar(pb, i/(length(packages)+1), label = sprintf('Loading package-%s', packages[i]))
library(packages[i], character.only = TRUE)
}
setWinProgressBar(pb, 1.00, label = 'Starting application')
close(pb)
## app is launched in the system default browser (if FF or Chrome, should work fine, IE needs to be >= 10)
#runApp("./app/shiny/", launch.browser=TRUE)
source('./app/app.R')
'application terminated normally'
},
error = function(e) {
msg = sprintf('Startup failed with error(s):\n\n%s', e$message)
tcltk::tk_messageBox(
type="ok",
message=msg,
icon="error")
msg
},
finally = {
close(pb)
})
message(appexit_msg)