Commit 9b5be606 authored by mmassaviol's avatar mmassaviol
Browse files

Update SAG (output dir is now a parameter)

parent 14262083
#!/usr/bin Rscript
# This script will take a SAG yaml configuration file and generate a ShinyApp
# Accepts one parameters: path to sag yaml configuration file
# Usage: Rscript /path/to/sag.yaml
# Accepts two parameters: path to sag yaml configuration file
# Usage: Rscript /path/to/sag.yaml /output/dir/
args = commandArgs(trailingOnly=TRUE)
source("tools.R")
library(yaml)
path_yml <- args[1]
output_dir <- args[2]
APP <<- yaml.load_file(path_yml,handlers = list("float#fix"=function(x){ format(x,scientific=F)}))$App
generate_added_styles <- function () {
path_css = APP$project + "/www/added_styles.css"
path_css = output_dir + "/www/added_styles.css"
file.replace(path_css)
}
......@@ -256,7 +257,7 @@ generate_pages_server <- function() {
for(x in 1:length(APP$pages)) {
name <- APP$pages[[x]]$name
resG <- resG + "\t# \tPage : " + name + "\n"
path_page = APP$project+"/pages/pages_def_"+tolower(name)+".R"
path_page = output_dir+"/pages/pages_def_"+tolower(name)+".R"
file.replace(path_page)
res <- 'tab'+ name + ' = fluidPage(\n\n'
......@@ -317,7 +318,7 @@ generate_pages_server <- function() {
write(res, file=path_page)
path_opt = APP$project+"/server/opt_"+tolower(name)+".R"
path_opt = output_dir+"/server/opt_"+tolower(name)+".R"
#file.replace(path_opt)
res <- ""
......@@ -374,7 +375,7 @@ generate_pages_server <- function() {
# res <- res + '#\' Event when use '+ run$shiny_button$name +' button\n'
# res <- res + 'observeEvent(input$'+ run$shiny_button$name+', {\n\n'
# page_path <- APP$project + '/params/' + 'params_' + APP$pages[[x]]$name + '.yml'
# page_path <- output_dir + '/params/' + 'params_' + APP$pages[[x]]$name + '.yml'
# file.replace(page_path)
......@@ -601,7 +602,7 @@ generate_pages_server <- function() {
# res <- res + '\t}\n'
# res <- res + '}\n'
file.replace(APP$project+"/server/opt_global.R")
file.replace(output_dir+"/server/opt_global.R")
#res <- ""
# Event RULEGRAPH
if ("RULEGRAPH" %in% names(APP)){
......@@ -643,7 +644,7 @@ generate_pages_server <- function() {
res <- res + '\ttoggle_inputs(input_list,F,F)\n'
res <- res + '\tupdateTabsetPanel(session, "sidebarmenu", selected = "run_out")\n'
#panel_path <- APP$project + '/params/' + 'params_' + APP$pages[[x]]$name + '.yml'
#panel_path <- output_dir + '/params/' + 'params_' + APP$pages[[x]]$name + '.yml'
res <- res + '\tpath_param <- paste0(input$results_dir,"/params.yml")\n\n'
res <- res + '\t\tsave_params(path_param)\n'
......@@ -729,14 +730,14 @@ generate_pages_server <- function() {
}
}
write(res, APP$project+"/server/opt_global.R")
write(res, output_dir+"/server/opt_global.R")
}
#============================================================
generate_menu <- function() {
path_file = APP$project + "/R/menugauche.R"
path_file = output_dir + "/R/menugauche.R"
file.replace(path_file)
......@@ -848,32 +849,32 @@ generate <- function() {
#YML_TOOLS <<- get_predefined_tool(files_tools)
if(dir.exists(APP$project)) {
#unlink(APP$project, recursive=TRUE)
if(dir.exists(output_dir)) {
#unlink(output_dir, recursive=TRUE)
}
dir.create.not.exist(APP$project)
dir.create.not.exist(output_dir)
generate_app()
dir.create.not.exist(APP$project + "/R")
dir.create.not.exist(output_dir + "/R")
generate_menu()
dir.create.not.exist(APP$project + "/pages")
dir.create.not.exist(APP$project + "/server")
#dir.create.not.exist(APP$project + "/params")
dir.create.not.exist(output_dir + "/pages")
dir.create.not.exist(output_dir + "/server")
#dir.create.not.exist(output_dir + "/params")
generate_pages_server()
dir.create.not.exist(APP$project + "/www")
dir.create.not.exist(output_dir + "/www")
path_rproj = APP$project + "/" + basename(APP$project) + ".Rproj"
path_rproj = output_dir + "/" + basename(output_dir) + ".Rproj"
generate_rproj(path_rproj)
generate_added_styles()
file.copy("./tools/chooser.R", APP$project + "/R/")
file.copy("./tools/chooser-binding.js", APP$project + "/www/")
file.copy("./tools/chooser.R", output_dir + "/R/")
file.copy("./tools/chooser-binding.js", output_dir + "/www/")
print("Generate End")
}
......@@ -891,7 +892,7 @@ file.replace <- function(path) {
#============================================================
generate_app <- function() {
path_project = APP$project + "/app.R"
path_project = output_dir + "/app.R"
main = APP$general
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment