From 06caa95f5a6e2185b821ef868a26051be151e485 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 16 Apr 2024 10:35:33 +0200 Subject: [PATCH 01/41] move global, server, ui in app.R file --- inst/Dashboard/app.R | 86 +++++++++++++++++++++++++++++++++++++++++ inst/Dashboard/global.R | 22 ----------- inst/Dashboard/server.R | 14 ------- inst/Dashboard/ui.R | 51 ------------------------ 4 files changed, 86 insertions(+), 87 deletions(-) create mode 100644 inst/Dashboard/app.R delete mode 100644 inst/Dashboard/global.R delete mode 100644 inst/Dashboard/server.R delete mode 100644 inst/Dashboard/ui.R diff --git a/inst/Dashboard/app.R b/inst/Dashboard/app.R new file mode 100644 index 0000000..3168c7e --- /dev/null +++ b/inst/Dashboard/app.R @@ -0,0 +1,86 @@ +# Loading libraries +library(shiny) # Used as it is a shiny app +library(bs4Dash) # Used instead of shinydashboard to provide additional options +library(fresh) # Used to easily change css in bs4Dash +library(ggplot2) # Used for plotting +library(shinyMixR) # Used for everything else + +# Check and load nlmixr(2) +if ("nlmixr2" %in% rownames(installed.packages())){ + library(nlmixr2) +} else { + cat("you need the 'nlmixr2' package to run models\n") +} + +# Create theme for dashboard +newtheme <- create_theme( + theme = "darkly", # theme has no effect, at least within bs4Dash + bs4dash_font(size_base = "0.9rem"), + bs4dash_status(primary = "#3c8dbc") +) + +ui <- dashboardPage( + title = "shinyMixR", + # Header + header = dashboardHeader( + title = dashboardBrand(title = "ShinyMixR", color = "lightblue"), #, color = "lightblue", href = "#", image = "logoshinyMixR.png"), + leftUI = tags$img(src='logoshinyMixR.png',height=40) + ), + # Sidebar menu + sidebar = dashboardSidebar(status="lightblue", elevation = 1, + sidebarMenu(id="tabs", + menuItem('Model overview', tabName='overview', icon=icon('table')), + menuItem('Edit model(s)', tabName='editor', icon=icon('file-pen')), + menuItem('Run model(s)', tabName='run', icon=icon('person-running')), + menuItem('Parameter estimates', tabName='par', icon=icon('table-cells')), + menuItem('Goodness of fit', tabName='gof', icon=icon('chart-line')), + menuItem('Fit plots', tabName='fitpl', icon=icon('chart-line')), + menuItem('Data exploration', tabName='expl', icon=icon('magnifying-glass')), + menuItem('Settings', tabName='settings', icon=icon('gear')) + ) + ), + # Main body + body = dashboardBody( + # First set theme and include css + use_theme(newtheme), + # CHECK IF THE LINES BELOW WILL WORK WITHOUT INTERNET CONNECTION AND DOES IT FAIL GRACEFULLY?! + shinyWidgets::useSweetAlert("minimal"), + tags$style("@import url(https://use.fontawesome.com/releases/v6.3.0/css/all.css);"), + tags$head(tags$style(HTML(".shiny-split-layout > div {overflow: visible;}"))), + tags$head(tags$style("#progph{overflow-y:scroll; max-height: 600px;}")), + tags$head(tags$style(HTML("#exploretabout{height: 75vh; overflow-y: auto;}"))), + tags$head(tags$style(HTML(".swal2-popup {font-size: 0.9rem !important;}"))), + tags$head(tags$style(HTML("input[id$=\"subset\"]{font-family:\"Courier New\"}"))), + tags$head(tags$style(HTML("input[id$=\"precode\"]{font-family:\"Courier New\"}"))), + tags$head(tags$style(HTML("label{margin-bottom:0rem;}"))), + tabItems( + tabItem(tabName = "overview", module_overview_ui("oview")), + tabItem(tabName = "editor", module_edit_ui("editor")), + tabItem(tabName = "run", module_run_ui("modrun")), + tabItem(tabName = "par", module_pt_ui("partable")), + tabItem(tabName = "gof", module_gof_ui("gofplots")), + tabItem(tabName = "fitpl", module_fitplots_ui("fitplots")), + tabItem(tabName = "expl", module_dataexplore_ui("explore")), + tabItem(tabName = "settings", module_settings_ui("settings")) + ) + ) +) + +server <- function(input, output, session) { + + # Top-level reactive values + r <- reactiveValues(active_tab = "", + model_updated = 0) + observeEvent(input$tabs, r$active_tab <- input$tabs) + sett <- module_settings_server("settings") + module_overview_server("oview") + module_edit_server("editor", r = r, settings=sett) + module_run_server("modrun", r = r) + module_pt_server("partable", r = r) + module_gof_server("gofplots", r = r,settings=sett) + module_fitplots_server("fitplots", r = r,settings=sett) + module_dataexplore_server("explore", r = r) + +} + +shinyApp(ui = ui, server = server) diff --git a/inst/Dashboard/global.R b/inst/Dashboard/global.R deleted file mode 100644 index fff3fbd..0000000 --- a/inst/Dashboard/global.R +++ /dev/null @@ -1,22 +0,0 @@ -# Loading libraries -library(shiny) # Used as it is a shiny app -library(bs4Dash) # Used instead of shinydashboard to provide additional options -library(fresh) # Used to easily change css in bs4Dash -library(ggplot2) # Used for plotting -library(shinyMixR) # Used for everything else - -# Check and load nlmixr(2) -if("nlmixr2" %in% rownames(installed.packages())){ - library(nlmixr2) -}else if("nlmixr" %in% rownames(installed.packages())){ - library(nlmixr) -}else{ - cat("you need either the 'nlmixr' or 'nlmixr2' package to run models\n") -} - -# Create theme for dashboard -newtheme <- create_theme( - theme = "darkly", # theme has no effect, at least within bs4Dash - bs4dash_font(size_base = "0.9rem"), - bs4dash_status(primary = "#3c8dbc") -) \ No newline at end of file diff --git a/inst/Dashboard/server.R b/inst/Dashboard/server.R deleted file mode 100644 index f99ffc3..0000000 --- a/inst/Dashboard/server.R +++ /dev/null @@ -1,14 +0,0 @@ -server <- function(input, output, session) { - # Top-level reactive values - r <- reactiveValues(active_tab = "", - model_updated = 0) - observeEvent(input$tabs, r$active_tab <- input$tabs) - sett <- module_settings_server("settings") - module_overview_server("oview") - module_edit_server("editor", r = r, settings=sett) - module_run_server("modrun", r = r) - module_pt_server("partable", r = r) - module_gof_server("gofplots", r = r,settings=sett) - module_fitplots_server("fitplots", r = r,settings=sett) - module_dataexplore_server("explore", r = r) -} \ No newline at end of file diff --git a/inst/Dashboard/ui.R b/inst/Dashboard/ui.R deleted file mode 100644 index 2d11036..0000000 --- a/inst/Dashboard/ui.R +++ /dev/null @@ -1,51 +0,0 @@ -# We need the code below in the ui because of setting the working directory -assign("proj_obj",get_proj(),pos = .GlobalEnv) -dashboardPage( - title = "shinyMixR", - # skin = "orange", - # controlbar = dashboardControlbar(skinSelector(), pinned = TRUE), - # Header - header = dashboardHeader( - title = dashboardBrand(title = "ShinyMixR", color = "lightblue"), #, color = "lightblue", href = "#", image = "logoshinyMixR.png"), - leftUI = tags$img(src='logoshinyMixR.png',height=40) - ), - # Sidebar menu - sidebar = dashboardSidebar(status="lightblue", elevation = 1, - sidebarMenu(id="tabs", - menuItem('Model overview', tabName='overview', icon=icon('table')), - menuItem('Edit model(s)', tabName='editor', icon=icon('file-pen')), - menuItem('Run model(s)', tabName='run', icon=icon('person-running')), - menuItem('Parameter estimates', tabName='par', icon=icon('table-cells')), - menuItem('Goodness of fit', tabName='gof', icon=icon('chart-line')), - menuItem('Fit plots', tabName='fitpl', icon=icon('chart-line')), - menuItem('Data exploration', tabName='expl', icon=icon('magnifying-glass')), - menuItem('Settings', tabName='settings', icon=icon('gear')) - ) - ), - # Main body - body = dashboardBody( - # First set theme and include css - use_theme(newtheme), - # CHECK IF THE LINES BELOW WILL WORK WITHOUT INTERNET CONNECTION AND DOES IT FAIL GRACEFULLY?! - shinyWidgets::useSweetAlert("minimal"), - tags$style("@import url(https://use.fontawesome.com/releases/v6.3.0/css/all.css);"), - tags$head(tags$style(HTML(".shiny-split-layout > div {overflow: visible;}"))), - tags$head(tags$style("#progph{overflow-y:scroll; max-height: 600px;}")), - tags$head(tags$style(HTML("#exploretabout{height: 75vh; overflow-y: auto;}"))), - tags$head(tags$style(HTML(".swal2-popup {font-size: 0.9rem !important;}"))), - tags$head(tags$style(HTML("input[id$=\"subset\"]{font-family:\"Courier New\"}"))), - tags$head(tags$style(HTML("input[id$=\"precode\"]{font-family:\"Courier New\"}"))), - tags$head(tags$style(HTML("label{margin-bottom:0rem;}"))), - tabItems( - tabItem(tabName = "overview", module_overview_ui("oview")), - tabItem(tabName = "editor", module_edit_ui("editor")), - tabItem(tabName = "run", module_run_ui("modrun")), - tabItem(tabName = "par", module_pt_ui("partable")), - tabItem(tabName = "gof", module_gof_ui("gofplots")), - tabItem(tabName = "fitpl", module_fitplots_ui("fitplots")), - tabItem(tabName = "expl", module_dataexplore_ui("explore")), - tabItem(tabName = "settings", module_settings_ui("settings")) - ) - ) -) - From 1e05c13845e9c6340e63d9d78b4c91004c15e14b Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 16 Apr 2024 10:53:11 +0200 Subject: [PATCH 02/41] move to `www` folder --- inst/Dashboard/{ => www}/logoshinyMixR.png | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename inst/Dashboard/{ => www}/logoshinyMixR.png (100%) diff --git a/inst/Dashboard/logoshinyMixR.png b/inst/Dashboard/www/logoshinyMixR.png similarity index 100% rename from inst/Dashboard/logoshinyMixR.png rename to inst/Dashboard/www/logoshinyMixR.png From 05eb7d12a049ea232355ae8cc619d733c95e0b8e Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 16 Apr 2024 11:11:56 +0200 Subject: [PATCH 03/41] change `proj_obj` to be used in `r` --- R/module_edit.R | 30 +++++++++++++++--------------- R/module_fitplots.R | 5 +++-- R/module_gof.R | 5 +++-- R/module_metadata.R | 21 +++++++++++---------- R/module_overview.R | 11 ++++++----- R/module_partable.R | 7 ++++--- R/module_run.R | 9 +++++---- inst/Dashboard/app.R | 19 +++++++++++++------ 8 files changed, 60 insertions(+), 47 deletions(-) diff --git a/R/module_edit.R b/R/module_edit.R index bf5d1ab..f559542 100644 --- a/R/module_edit.R +++ b/R/module_edit.R @@ -28,9 +28,9 @@ module_edit_ui <- function(id) { module_edit_server <- function(id, r, settings) { moduleServer(id, function(input, output, session) { # Adapt model list based on selected project location - observeEvent(r$active_tab,{ + observeEvent(r$active_tab, { if(r$active_tab=="editor"){ - updateSelectInput(session, "editLst", choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"],selected=input$editLst) + updateSelectInput(session, "editLst", choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=input$editLst) } },ignoreInit=TRUE) @@ -41,7 +41,7 @@ module_edit_server <- function(id, r, settings) { # Update editor when selecting new model observeEvent(input$editLst,{ - shinyAce::updateAceEditor(session,"editor",value=paste(readLines(proj_obj[[input$editLst]]$model),collapse="\n")) + shinyAce::updateAceEditor(session,"editor",value=paste(readLines(r$proj_obj[[input$editLst]]$model),collapse="\n")) },ignoreInit=TRUE) # New model @@ -63,8 +63,8 @@ module_edit_server <- function(id, r, settings) { if(!"try-error"%in%class(mdl)){ mdl <- sub("run1",sub("\\.[r|R]","",input$namenew),mdl) writeLines(mdl,paste0("models/",input$namenew)) - assign("proj_obj",get_proj(),pos = .GlobalEnv,inherits=TRUE) - updateSelectInput(session,"editLst",choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"],selected=sub("\\.[r|R]","",input$namenew)) + r$proj_obj <- get_proj() + updateSelectInput(session,"editLst",choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=sub("\\.[r|R]","",input$namenew)) shinyAce::updateAceEditor(session,"editor",value=paste(readLines(paste0("models/",input$namenew)),collapse="\n")) removeModal() } @@ -73,8 +73,8 @@ module_edit_server <- function(id, r, settings) { # Save model observeEvent(input$save,{ if(input$editLst!=""){ - writeLines(input$editor,proj_obj[[input$editLst]]$model) - assign("proj_obj",get_proj(),pos = .GlobalEnv,inherits=TRUE) + writeLines(input$editor,r$proj_obj[[input$editLst]]$model) + r$proj_obj <- get_proj() myalert("Model saved",type = "success") # Do not really like the alerts from bs4dash so stick to shinywdigets # createAlert(id = NULL,selector = NULL,options=list(title = "Alert",closable = TRUE,width = 12,elevations = 1,status = "primary",content = "Model saved")) @@ -84,11 +84,11 @@ module_edit_server <- function(id, r, settings) { # Handle meta data (we need to pass the selected model as a reactive) selectedmodel <- reactive(input$editLst) selectedcont <- reactive(input$editor) - upd <- module_metadata_server("adapt_meta_ed","save",sellmod=selectedmodel,sellcont=selectedcont) + upd <- module_metadata_server("adapt_meta_ed","save",sellmod=selectedmodel,sellcont=selectedcont,r=r) observeEvent(upd(),{ if(!is.null(upd())){ - updateSelectInput(session,"editLst",choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"],selected=sub("\\.[r|R]","",upd())) - shinyAce::updateAceEditor(session,"editor",value=paste(readLines(proj_obj[[sub("\\.[r|R]","",upd())]]$model),collapse="\n")) + updateSelectInput(session,"editLst",choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=sub("\\.[r|R]","",upd())) + shinyAce::updateAceEditor(session,"editor",value=paste(readLines(r$proj_obj[[sub("\\.[r|R]","",upd())]]$model),collapse="\n")) myalert(upd(),type = "success") } },ignoreInit=TRUE) @@ -97,8 +97,8 @@ module_edit_server <- function(id, r, settings) { initmodal <- function(){ ns <- session$ns if(isTruthy(input$editLst)){ - selm <- tools::file_path_sans_ext(basename(proj_obj[[input$editLst]]$model)) - incm <- incr_mdl(basename(proj_obj[[input$editLst]]$model),"models") + selm <- tools::file_path_sans_ext(basename(r$proj_obj[[input$editLst]]$model)) + incm <- incr_mdl(basename(r$proj_obj[[input$editLst]]$model),"models") }else{ selm <- incm <- NULL } @@ -118,9 +118,9 @@ module_edit_server <- function(id, r, settings) { if("try-error"%in%class(res)){ myalert("Could not update initials",type = "error") }else{ - assign("proj_obj",get_proj(),pos = .GlobalEnv,inherits=TRUE) - updateSelectInput(session,"editLst",choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"],selected=sub("\\.[r|R]","",input$tosave)) - shinyAce::updateAceEditor(session,"editor",value=paste(readLines(proj_obj[[sub("\\.[r|R]","",input$tosave)]]$model),collapse="\n")) + r$proj_obj <- get_proj() + updateSelectInput(session,"editLst",choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=sub("\\.[r|R]","",input$tosave)) + shinyAce::updateAceEditor(session,"editor",value=paste(readLines(r$proj_obj[[sub("\\.[r|R]","",input$tosave)]]$model),collapse="\n")) myalert("Initials updated",type = "success") } }else{ diff --git a/R/module_fitplots.R b/R/module_fitplots.R index ff53105..96dec25 100644 --- a/R/module_fitplots.R +++ b/R/module_fitplots.R @@ -4,9 +4,10 @@ #' @description Shiny module for fit plots #' #' @param id Module id +#' @param proj_obj Project object #' #' @export -module_fitplots_ui <- function(id) { +module_fitplots_ui <- function(id, proj_obj) { ns <- NS(id) tagList( fluidRow( @@ -46,7 +47,7 @@ module_fitplots_server <- function(id, r, settings) { # Adapt model list based on selected project location observeEvent(r$active_tab,{ if(r$active_tab=="fitpl"){ - updateSelectInput(session, "fitLst", choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"],selected=input$fitLst) + updateSelectInput(session, "fitLst", choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=input$fitLst) } },ignoreInit=TRUE) diff --git a/R/module_gof.R b/R/module_gof.R index 15a6b0e..e625c58 100644 --- a/R/module_gof.R +++ b/R/module_gof.R @@ -4,9 +4,10 @@ #' @description Shiny module for GOF plots #' #' @param id Module id +#' @param proj_obj Project object #' #' @export -module_gof_ui <- function(id) { +module_gof_ui <- function(id, proj_obj) { ns <- NS(id) tagList( fluidRow( @@ -42,7 +43,7 @@ module_gof_server <- function(id, r, settings) { # Adapt model list based on selected project location observeEvent(r$active_tab,{ if(r$active_tab=="gof"){ - updateSelectInput(session, "gofLst", choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"],selected=input$gofLst) + updateSelectInput(session, "gofLst", choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=input$gofLst) } },ignoreInit=TRUE) diff --git a/R/module_metadata.R b/R/module_metadata.R index 1215be0..8df7166 100644 --- a/R/module_metadata.R +++ b/R/module_metadata.R @@ -22,9 +22,10 @@ module_metadata_ui <- function(id,type) { #' @param selline reactive with the selected line for a model (for type "overview") #' @param sellmod reactive with the selected model (for type "save") #' @param sellcont reactive with the content of the selected model (for type "save") +#' @param r reactive values object that is defined top-level #' #' @export -module_metadata_server <- function(id,type,selline=NULL,sellmod=NULL,sellcont=NULL){ +module_metadata_server <- function(id,type,selline=NULL,sellmod=NULL,sellcont=NULL,r){ moduleServer(id, function(input, output, session){ # Function for the modal @@ -37,17 +38,17 @@ module_metadata_server <- function(id,type,selline=NULL,sellmod=NULL,sellcont=NU titl <- ifelse(type=="save","Save as","Adapt model info") meta <- list(mdls="",imp=0,ref="",desc="",est="saem",data="",sel="") - if(!is.null(selline)) meta$sel <- sort(names(proj_obj)[names(proj_obj)!="meta"])[selline()] + if(!is.null(selline)) meta$sel <- sort(names(r$proj_obj)[names(r$proj_obj)!="meta"])[selline()] if(!is.null(sellmod)) meta$sel <- sellmod() if(length(meta$sel)==0 || meta$sel=="") return() - meta$imp <- proj_obj[[meta$sel]]$modeleval$meta$imp - meta$ref <- proj_obj[[meta$sel]]$modeleval$meta$ref - meta$desc <- proj_obj[[meta$sel]]$modeleval$meta$desc - meta$est <- proj_obj[[meta$sel]]$modeleval$meta$est - meta$data <- proj_obj[[meta$sel]]$modeleval$meta$data + meta$imp <- r$proj_obj[[meta$sel]]$modeleval$meta$imp + meta$ref <- r$proj_obj[[meta$sel]]$modeleval$meta$ref + meta$desc <- r$proj_obj[[meta$sel]]$modeleval$meta$desc + meta$est <- r$proj_obj[[meta$sel]]$modeleval$meta$est + meta$data <- r$proj_obj[[meta$sel]]$modeleval$meta$data - meta$mdls <- c("",names(proj_obj)[names(proj_obj)!="meta"]) + meta$mdls <- c("",names(r$proj_obj)[names(r$proj_obj)!="meta"]) gen <- tagList( sliderInput(ns("mdlimp"), "Importance", 0, 4, meta$imp, step = 1, round = TRUE), @@ -72,7 +73,7 @@ module_metadata_server <- function(id,type,selline=NULL,sellmod=NULL,sellcont=NU observeEvent(input$mdladpt,{ if(type!="save"){ if(input$mdladpt!=''){ - meta <- proj_obj[[input$mdladpt]]$modeleval$meta + meta <- r$proj_obj[[input$mdladpt]]$modeleval$meta updateSliderInput(session,"mdlimp",value=meta$imp) updateTextInput(session,"mdldesc",value=meta$desc) updateSelectInput(session,"mdlref",selected=meta$ref) @@ -105,7 +106,7 @@ module_metadata_server <- function(id,type,selline=NULL,sellmod=NULL,sellcont=NU towr <- adpt_meta(toret['name'],metanfo) if(type=="save") towr <- sub(sellmod(),sub("\\.[r|R]","",input$mdladpt),towr) writeLines(towr,toret['saveas']) - assign("proj_obj",get_proj(),pos = .GlobalEnv,inherits=TRUE) + r$proj_obj <- get_proj() removeModal() meta_ret(toret['val']) } diff --git a/R/module_overview.R b/R/module_overview.R index c379423..afa0b0a 100644 --- a/R/module_overview.R +++ b/R/module_overview.R @@ -32,9 +32,10 @@ module_overview_ui <- function(id) { #' Overview module for server #' #' @param id Module id +#' @param r reactive values object that is defined top-level #' #' @export -module_overview_server <- function(id) { +module_overview_server <- function(id, r) { moduleServer(id, function(input, output, session){ # Make reactive value to hold the available models/scripts rv <- reactiveValues(mdls=list.files("models",pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE),scrpt=list.files("scripts",full.names = TRUE)) @@ -58,7 +59,7 @@ module_overview_server <- function(id) { # Refresh overview observeEvent(input$overview_refr,{ if(file.exists("shinyMixR")){ - assign("proj_obj",get_proj(),pos = .GlobalEnv) + r$proj_obj <- get_proj() overview_ov <- overview() DT::replaceData(proxy, overview_ov, rownames = FALSE) rv$mdls <- list.files("models",pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE) @@ -81,7 +82,7 @@ module_overview_server <- function(id) { modalDialog(title="High level results",easyClose = TRUE,size="l",verbatimTextOutput(ns("res_out"))) } hr_out <- eventReactive(input$hlr, { - sel <- sort(names(proj_obj)[names(proj_obj)!="meta"])[input$overview_tbl_rows_selected] + sel <- sort(names(r$proj_obj)[names(r$proj_obj)!="meta"])[input$overview_tbl_rows_selected] if(length(sel)>0){ res <- try(readRDS(paste0("shinyMixR/",sel[1],".res.rds"))) if(!"try-error"%in%class(res)) print(res) else print("No results available") @@ -100,14 +101,14 @@ module_overview_server <- function(id) { observeEvent(input$del,{showModal(delmodal())},ignoreInit = TRUE) observeEvent(input$del2,{ if(!is.null(input$overview_tbl_rows_selected)){ - msel <- sort(names(proj_obj)[names(proj_obj)!="meta"])[input$overview_tbl_rows_selected] + msel <- sort(names(r$proj_obj)[names(r$proj_obj)!="meta"])[input$overview_tbl_rows_selected] if(input$delmodall) { try(file.remove(paste0("shinyMixR/",msel,".res.rds"))) try(file.remove(paste0("shinyMixR/",msel,".ressum.rds"))) try(unlink(paste0("analysis/",msel),recursive = TRUE)) } try(file.remove(paste0("models/",msel,".r"))) - assign("proj_obj",get_proj(),pos = .GlobalEnv,inherits=TRUE) + r$proj_obj <- get_proj() DT::replaceData(proxy, overview(), rownames = FALSE) removeModal() } diff --git a/R/module_partable.R b/R/module_partable.R index 738c355..4865f2a 100644 --- a/R/module_partable.R +++ b/R/module_partable.R @@ -4,9 +4,10 @@ #' @description Shiny module for parameter table #' #' @param id Module id +#' @param proj_obj Project object #' #' @export -module_pt_ui <- function(id) { +module_pt_ui <- function(id, proj_obj) { ns <- NS(id) tagList( actionButton(ns("savePars"), "Save parameter table",icon=icon("floppy-disk")),br(),br(), @@ -35,8 +36,8 @@ module_pt_server <- function(id, r) { if(r$active_tab=="par"){ updateSelectInput(session, "EstLst", - choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"], - selected= ifelse(is.null(input$EstLst), names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"][1], input$EstLst) + choices = names(r$proj_obj)[names(r$proj_obj)!="meta"], + selected= ifelse(is.null(input$EstLst), names(r$proj_obj)[names(r$proj_obj)!="meta"][1], input$EstLst) ) } },ignoreInit=TRUE) diff --git a/R/module_run.R b/R/module_run.R index 37dbf90..135309f 100644 --- a/R/module_run.R +++ b/R/module_run.R @@ -4,9 +4,10 @@ #' @description Shiny module for running models #' #' @param id Module id +#' @param proj_obj Project object #' #' @export -module_run_ui <- function(id) { +module_run_ui <- function(id, proj_obj) { ns <- NS(id) tagList( selectInput(ns("runLst"),"Model(s)",names(proj_obj)[names(proj_obj)!="meta"],multiple=TRUE,selectize = TRUE), @@ -30,7 +31,7 @@ module_run_server <- function(id, r) { # Adapt/update model list observeEvent(r$active_tab,{ if(r$active_tab=="run"){ - updateSelectInput(session, "runLst", choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"],selected=input$runmod_runLst) + updateSelectInput(session, "runLst", choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=input$runmod_runLst) } },ignoreInit=TRUE) @@ -39,7 +40,7 @@ module_run_server <- function(id, r) { unlink(list.files(paste0("shinyMixR/temp"),pattern=".*prog\\.txt$",full.names = TRUE)) # Perform tests before running if(!is.null(input$runLst)){ - proj <- get("proj_obj",pos = .GlobalEnv) + proj <- r$proj_obj checkall <- unlist(sapply(input$runLst,function(x){ chk <- proj[[x]]$model chksrc <- try(source(chk,local=TRUE),silent=TRUE) @@ -55,7 +56,7 @@ module_run_server <- function(id, r) { myalert("model(s) submitted, wait for progress log to pop-up!",type = "succes") addcwres <- ifelse("Add CWRES to output"%in%input$addExtra,TRUE,FALSE) addnpde <- ifelse("Add NPDE to output"%in%input$addExtra,TRUE,FALSE) - lapply(input$runLst,function(mods) run_nmx(mods,proj_obj,addcwres=addcwres,addnpde=addnpde)) + lapply(input$runLst,function(mods) run_nmx(mods,r$proj_obj,addcwres=addcwres,addnpde=addnpde)) } }else{ myalert("Please select models to run",type = "error") diff --git a/inst/Dashboard/app.R b/inst/Dashboard/app.R index 3168c7e..e7fe0bb 100644 --- a/inst/Dashboard/app.R +++ b/inst/Dashboard/app.R @@ -12,6 +12,9 @@ if ("nlmixr2" %in% rownames(installed.packages())){ cat("you need the 'nlmixr2' package to run models\n") } +# Initiate project +proj_obj <- create_proj() + # Create theme for dashboard newtheme <- create_theme( theme = "darkly", # theme has no effect, at least within bs4Dash @@ -56,10 +59,10 @@ ui <- dashboardPage( tabItems( tabItem(tabName = "overview", module_overview_ui("oview")), tabItem(tabName = "editor", module_edit_ui("editor")), - tabItem(tabName = "run", module_run_ui("modrun")), - tabItem(tabName = "par", module_pt_ui("partable")), - tabItem(tabName = "gof", module_gof_ui("gofplots")), - tabItem(tabName = "fitpl", module_fitplots_ui("fitplots")), + tabItem(tabName = "run", module_run_ui("modrun", proj_obj)), + tabItem(tabName = "par", module_pt_ui("partable", proj_obj)), + tabItem(tabName = "gof", module_gof_ui("gofplots", proj_obj)), + tabItem(tabName = "fitpl", module_fitplots_ui("fitplots", proj_obj)), tabItem(tabName = "expl", module_dataexplore_ui("explore")), tabItem(tabName = "settings", module_settings_ui("settings")) ) @@ -70,10 +73,14 @@ server <- function(input, output, session) { # Top-level reactive values r <- reactiveValues(active_tab = "", - model_updated = 0) + model_updated = 0, + proj_obj = get_proj()) + observeEvent(input$tabs, r$active_tab <- input$tabs) + + # Modules sett <- module_settings_server("settings") - module_overview_server("oview") + module_overview_server("oview", r = r) module_edit_server("editor", r = r, settings=sett) module_run_server("modrun", r = r) module_pt_server("partable", r = r) From 7fa030942886ba1c30ba6956c6ba9893020b57f5 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 16 Apr 2024 11:12:31 +0200 Subject: [PATCH 04/41] docs: add `r` and `proj_obj` as args --- man/module_fitplots_ui.Rd | 4 +++- man/module_gof_ui.Rd | 4 +++- man/module_metadata_server.Rd | 5 ++++- man/module_overview_server.Rd | 4 +++- man/module_pt_ui.Rd | 4 +++- man/module_run_ui.Rd | 4 +++- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/man/module_fitplots_ui.Rd b/man/module_fitplots_ui.Rd index 6515ac8..38e5760 100644 --- a/man/module_fitplots_ui.Rd +++ b/man/module_fitplots_ui.Rd @@ -4,10 +4,12 @@ \alias{module_fitplots_ui} \title{Fit plots module for UI} \usage{ -module_fitplots_ui(id) +module_fitplots_ui(id, proj_obj) } \arguments{ \item{id}{Module id} + +\item{proj_obj}{Project object} } \description{ Shiny module for fit plots diff --git a/man/module_gof_ui.Rd b/man/module_gof_ui.Rd index 05209dc..26f7132 100644 --- a/man/module_gof_ui.Rd +++ b/man/module_gof_ui.Rd @@ -4,10 +4,12 @@ \alias{module_gof_ui} \title{GOF plots module for UI} \usage{ -module_gof_ui(id) +module_gof_ui(id, proj_obj) } \arguments{ \item{id}{Module id} + +\item{proj_obj}{Project object} } \description{ Shiny module for GOF plots diff --git a/man/module_metadata_server.Rd b/man/module_metadata_server.Rd index dbdf2b0..26239b2 100644 --- a/man/module_metadata_server.Rd +++ b/man/module_metadata_server.Rd @@ -9,7 +9,8 @@ module_metadata_server( type, selline = NULL, sellmod = NULL, - sellcont = NULL + sellcont = NULL, + r ) } \arguments{ @@ -22,6 +23,8 @@ module_metadata_server( \item{sellmod}{reactive with the selected model (for type "save")} \item{sellcont}{reactive with the content of the selected model (for type "save")} + +\item{r}{reactive values object that is defined top-level} } \description{ meta data module for server diff --git a/man/module_overview_server.Rd b/man/module_overview_server.Rd index fb2f453..f329d51 100644 --- a/man/module_overview_server.Rd +++ b/man/module_overview_server.Rd @@ -4,10 +4,12 @@ \alias{module_overview_server} \title{Overview module for server} \usage{ -module_overview_server(id) +module_overview_server(id, r) } \arguments{ \item{id}{Module id} + +\item{r}{reactive values object that is defined top-level} } \description{ Overview module for server diff --git a/man/module_pt_ui.Rd b/man/module_pt_ui.Rd index 6e4f5e1..a5db8f3 100644 --- a/man/module_pt_ui.Rd +++ b/man/module_pt_ui.Rd @@ -4,10 +4,12 @@ \alias{module_pt_ui} \title{Parameter table module for UI} \usage{ -module_pt_ui(id) +module_pt_ui(id, proj_obj) } \arguments{ \item{id}{Module id} + +\item{proj_obj}{Project object} } \description{ Shiny module for parameter table diff --git a/man/module_run_ui.Rd b/man/module_run_ui.Rd index beacf0c..d51d00e 100644 --- a/man/module_run_ui.Rd +++ b/man/module_run_ui.Rd @@ -4,10 +4,12 @@ \alias{module_run_ui} \title{Run model module for UI} \usage{ -module_run_ui(id) +module_run_ui(id, proj_obj) } \arguments{ \item{id}{Module id} + +\item{proj_obj}{Project object} } \description{ Shiny module for running models From c08a29069c4d74037325943f2accd2b5c853d5de Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 16 Apr 2024 11:21:31 +0200 Subject: [PATCH 05/41] source correct files --- R/run_shinymixr.r | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/R/run_shinymixr.r b/R/run_shinymixr.r index 8d49087..77880e0 100644 --- a/R/run_shinymixr.r +++ b/R/run_shinymixr.r @@ -15,18 +15,12 @@ #' run_shinymixr(".") #' } run_shinymixr <- function(wd = getwd(), dry_run = FALSE, ...){ + if(!file.exists(paste0(wd,"/shinyMixR/app/www"))) try(dir.create(paste0(wd,"/shinyMixR/app/www"),recursive = TRUE)) - #if(!file.exists(paste0(wd,"/shinyMixR/app/R"))) try(dir.create(paste0(wd,"/shinyMixR/app/R"),recursive = TRUE)) if(!file.exists(paste0(wd,"/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/temp"),recursive=TRUE)) - try(file.copy(system.file("Dashboard","global.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/global.R"),overwrite = TRUE),silent = TRUE) - try(file.copy(system.file("Dashboard","server.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/server.R"),overwrite = TRUE),silent = TRUE) - try(file.copy(system.file("Dashboard","logoshinyMixR.png",package="shinyMixR"), paste0(wd,"/shinyMixR/app/www/logoshinyMixR.png")),silent = TRUE) - - # We need to add the working directory to the ui.r file (global.r does not work) - adpt <- readLines(system.file("Dashboard","ui.R",package="shinyMixR")) - adpt <- c(paste0("setwd(\"",normalizePath(wd,winslash = "/"),"\")"),adpt) - writeLines(adpt,paste0(wd,"/shinyMixR/app/ui.R")) + try(file.copy(system.file("Dashboard","app.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/app.R"),overwrite = TRUE),silent = TRUE) + try(file.copy(system.file("Dashboard","www/logoshinyMixR.png",package="shinyMixR"), paste0(wd,"/shinyMixR/app/www/logoshinyMixR.png")),silent = TRUE) # Clean up stuff before running the app (check if feasible or not) try(unlink(list.files(paste0(wd,"/shinyMixR/temp"),pattern=".*prog\\.txt$",full.names = TRUE))) From 6c2e68b742f7107796414e3701c808a56da6fef9 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 16 Apr 2024 13:17:55 +0200 Subject: [PATCH 06/41] use `get_proj` instead of `create_proj` --- inst/Dashboard/app.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/Dashboard/app.R b/inst/Dashboard/app.R index e7fe0bb..0142293 100644 --- a/inst/Dashboard/app.R +++ b/inst/Dashboard/app.R @@ -13,7 +13,7 @@ if ("nlmixr2" %in% rownames(installed.packages())){ } # Initiate project -proj_obj <- create_proj() +proj_obj <- get_proj() # Create theme for dashboard newtheme <- create_theme( From fde9040c47aac9d4247f5e0efcfcefe4f5e0e206 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 16 Apr 2024 14:20:32 +0200 Subject: [PATCH 07/41] use correct wd + introduce `this_wd` + rework overview --- R/module_edit.R | 6 +++--- R/module_metadata.R | 2 +- R/module_overview.R | 42 ++++++++++++++++++++++++------------------ R/overview.r | 14 +++++++------- R/run_shinymixr.r | 7 ++++++- R/tree_overview.r | 7 ++++--- inst/Dashboard/app.R | 7 +++++-- 7 files changed, 50 insertions(+), 35 deletions(-) diff --git a/R/module_edit.R b/R/module_edit.R index f559542..29b932a 100644 --- a/R/module_edit.R +++ b/R/module_edit.R @@ -63,7 +63,7 @@ module_edit_server <- function(id, r, settings) { if(!"try-error"%in%class(mdl)){ mdl <- sub("run1",sub("\\.[r|R]","",input$namenew),mdl) writeLines(mdl,paste0("models/",input$namenew)) - r$proj_obj <- get_proj() + r$proj_obj <- get_proj(r$this_wd) updateSelectInput(session,"editLst",choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=sub("\\.[r|R]","",input$namenew)) shinyAce::updateAceEditor(session,"editor",value=paste(readLines(paste0("models/",input$namenew)),collapse="\n")) removeModal() @@ -74,7 +74,7 @@ module_edit_server <- function(id, r, settings) { observeEvent(input$save,{ if(input$editLst!=""){ writeLines(input$editor,r$proj_obj[[input$editLst]]$model) - r$proj_obj <- get_proj() + r$proj_obj <- get_proj(r$this_wd) myalert("Model saved",type = "success") # Do not really like the alerts from bs4dash so stick to shinywdigets # createAlert(id = NULL,selector = NULL,options=list(title = "Alert",closable = TRUE,width = 12,elevations = 1,status = "primary",content = "Model saved")) @@ -118,7 +118,7 @@ module_edit_server <- function(id, r, settings) { if("try-error"%in%class(res)){ myalert("Could not update initials",type = "error") }else{ - r$proj_obj <- get_proj() + r$proj_obj <- get_proj(r$this_wd) updateSelectInput(session,"editLst",choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=sub("\\.[r|R]","",input$tosave)) shinyAce::updateAceEditor(session,"editor",value=paste(readLines(r$proj_obj[[sub("\\.[r|R]","",input$tosave)]]$model),collapse="\n")) myalert("Initials updated",type = "success") diff --git a/R/module_metadata.R b/R/module_metadata.R index 8df7166..1f6463f 100644 --- a/R/module_metadata.R +++ b/R/module_metadata.R @@ -106,7 +106,7 @@ module_metadata_server <- function(id,type,selline=NULL,sellmod=NULL,sellcont=NU towr <- adpt_meta(toret['name'],metanfo) if(type=="save") towr <- sub(sellmod(),sub("\\.[r|R]","",input$mdladpt),towr) writeLines(towr,toret['saveas']) - r$proj_obj <- get_proj() + r$proj_obj <- get_proj(r$this_wd) removeModal() meta_ret(toret['val']) } diff --git a/R/module_overview.R b/R/module_overview.R index afa0b0a..1ba2ecf 100644 --- a/R/module_overview.R +++ b/R/module_overview.R @@ -37,33 +37,39 @@ module_overview_ui <- function(id) { #' @export module_overview_server <- function(id, r) { moduleServer(id, function(input, output, session){ - # Make reactive value to hold the available models/scripts - rv <- reactiveValues(mdls=list.files("models",pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE),scrpt=list.files("scripts",full.names = TRUE)) - # Create overview when app is loaded - if(all(file.exists(c("analysis","data","models","scripts","shinyMixR")))){ - overview_ov <- overview() - }else{ - overview_ov <- data.frame(models="",importance="",description="",ref="",data="",method="",OBJF="",dOBJF=NA,runtime="") - } + observe({ + + # Make reactive value to hold the available models/scripts + r$mdls <- list.files(paste0(r$this_wd, "/models"), pattern = "run[[:digit:]]*\\.[r|R]", full.names = TRUE) + r$scrpt <- list.files(paste0(r$this_wd, "/scripts"), full.names = TRUE) + + # if no models are present in r$proj_obj, return empty table + if (length(names(r$proj_obj)[names(r$proj_obj) != "meta"]) > 0) { + r$overview_ov <- overview(r$proj_obj) + } else { + r$overview_ov <- data.frame(models="",importance="",description="",ref="",data="",method="",OBJF="",dOBJF=NA,runtime="") + } + }) + proxy = DT::dataTableProxy("overview_tbl") - output$overview_tbl = DT::renderDataTable(overview_ov,rownames=FALSE,extension=c("Buttons"), options=list(scrollX=TRUE,dom="Bfrtip",buttons=c('colvis','csv'),pageLength=100,lengthMenu=c(10,100,1000,10000))) + output$overview_tbl = DT::renderDataTable(r$overview_ov,rownames=FALSE,extension=c("Buttons"), options=list(scrollX=TRUE,dom="Bfrtip",buttons=c('colvis','csv'),pageLength=100,lengthMenu=c(10,100,1000,10000))) # filter="bottom", --> bug with filters/module/modal # Create tree tree <- eventReactive(input$mktree,{ - if(file.exists("shinyMixR")){tree_overview()}else{data.frame()} + if(file.exists("shinyMixR")){tree_overview(r$proj_obj)}else{data.frame()} }) output$treeout <- collapsibleTree::renderCollapsibleTree(tree()) # Refresh overview observeEvent(input$overview_refr,{ if(file.exists("shinyMixR")){ - r$proj_obj <- get_proj() - overview_ov <- overview() + r$proj_obj <- get_proj(r$this_wd) + overview_ov <- overview(r$proj_obj) DT::replaceData(proxy, overview_ov, rownames = FALSE) - rv$mdls <- list.files("models",pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE) - rv$scrpt <- list.files("scripts",full.names = TRUE) + r$mdls <- list.files("models",pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE) + r$scrpt <- list.files("scripts",full.names = TRUE) } },ignoreInit = TRUE) @@ -73,7 +79,7 @@ module_overview_server <- function(id, r) { }) upd <- module_metadata_server("adapt_meta_ov","overview",selline=selectedLine) observeEvent(upd(),{ - if(upd()=="Update DT") DT::replaceData(proxy, overview(), rownames = FALSE) + if(upd()=="Update DT") DT::replaceData(proxy, overview(r$proj_obj), rownames = FALSE) }) # Show high level results @@ -108,15 +114,15 @@ module_overview_server <- function(id, r) { try(unlink(paste0("analysis/",msel),recursive = TRUE)) } try(file.remove(paste0("models/",msel,".r"))) - r$proj_obj <- get_proj() - DT::replaceData(proxy, overview(), rownames = FALSE) + r$proj_obj <- get_proj(r$this_wd) + DT::replaceData(proxy, overview(r$proj_obj), rownames = FALSE) removeModal() } },ignoreInit = TRUE) # Running scripts - Check creation of temp folder (should be done in create_proj (get_proj) function?) dir.create("shinyMixR/temp",showWarnings = FALSE,recursive = TRUE) - module_scripts_server("runscripts", files = reactive(rv$mdls), scripts = reactive(rv$scrpt), loc = "shinyMixR/temp") + module_scripts_server("runscripts", files = reactive(r$mdls), scripts = reactive(r$scrpt), loc = "shinyMixR/temp") # Creating reports module_reports_server("reports") diff --git a/R/overview.r b/R/overview.r index 4069321..c36ac2f 100644 --- a/R/overview.r +++ b/R/overview.r @@ -4,6 +4,7 @@ #' Create an overview of the models within a project. This overview includes the meta data #' of the models and if results are available, also the objective function and run-times #' +#' @param proj_obj a project object created with \code{\link{get_proj}} #' @param ... additional arguments passed to \code{\link{get_proj}} #' #' @export @@ -12,21 +13,20 @@ #' @examples #' #' \dontrun{ -#' overview() +#' overview(proj_obj) #' } -overview <- function(...){ - obj <- get_proj(...) - mdln <- names(obj)[names(obj)!="meta"] +overview <- function(proj_obj, ...){ + mdln <- names(proj_obj)[names(proj_obj)!="meta"] res1 <- lapply(mdln, function(x){ - if(class(obj[[x]]$modeleval)=="try-error" || class(obj[[x]]$modeleval$meta)=="try-error"){ + if(class(proj_obj[[x]]$modeleval)=="try-error" || class(proj_obj[[x]]$modeleval$meta)=="try-error"){ c(NA,"","","","") }else{ - meta <- obj[[x]]$modeleval$meta + meta <- proj_obj[[x]]$modeleval$meta c(ifelse(is.null(meta$imp),NA,meta$imp), ifelse(is.null(meta$desc),"",meta$desc),ifelse(is.null(meta$ref),"",meta$ref), ifelse(is.null(meta$data),"",meta$data),ifelse(is.null(meta$est),"",meta$est)) } }) - res2 <- lapply(obj[mdln], function(x){ + res2 <- lapply(proj_obj[mdln], function(x){ if(!is.null(x$results)) c(round(x$results$OBJF,3),round(x$results$tottime,3)) else c("","") }) res <- data.frame(cbind(mdln,do.call(rbind,res1),do.call(rbind,res2)),stringsAsFactors = FALSE) diff --git a/R/run_shinymixr.r b/R/run_shinymixr.r index 77880e0..74584fd 100644 --- a/R/run_shinymixr.r +++ b/R/run_shinymixr.r @@ -21,7 +21,12 @@ run_shinymixr <- function(wd = getwd(), dry_run = FALSE, ...){ try(file.copy(system.file("Dashboard","app.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/app.R"),overwrite = TRUE),silent = TRUE) try(file.copy(system.file("Dashboard","www/logoshinyMixR.png",package="shinyMixR"), paste0(wd,"/shinyMixR/app/www/logoshinyMixR.png")),silent = TRUE) - + + # Set the working directory so the project can be found + adpt <- readLines(system.file("Dashboard", "app.R", package = "shinyMixR")) + adpt <- c(paste0("setwd(\"", normalizePath(wd, winslash = "/"), "\")"), adpt) + writeLines(adpt, paste0(wd,"/shinyMixR/app/app.R")) + # Clean up stuff before running the app (check if feasible or not) try(unlink(list.files(paste0(wd,"/shinyMixR/temp"),pattern=".*prog\\.txt$",full.names = TRUE))) if (dry_run == TRUE) { diff --git a/R/tree_overview.r b/R/tree_overview.r index 0781893..535c577 100644 --- a/R/tree_overview.r +++ b/R/tree_overview.r @@ -5,6 +5,7 @@ #' This is mostly relevant in case the reference of models is included to #' visualise the relationship between models #' +#' @param proj_obj a project object created with \code{\link{get_proj}} #' @param ... additional arguments passed to \code{\link{overview}} #' #' @export @@ -14,10 +15,10 @@ #' @examples #' #' \dontrun{ -#' tree_overview() +#' tree_overview(proj_obj) #' } -tree_overview <- function(...){ - tmod <- overview(...) +tree_overview <- function(proj_obj, ...){ + tmod <- overview(proj_obj, ...) stmodn <- data.frame(from=NA,to="start",imp=0,stringsAsFactors = FALSE) noref <- data.frame(from="start",to=tmod$models[tmod$ref==""],imp=tmod$imp[tmod$ref==""],stringsAsFactors = FALSE) refs <- data.frame(from=tmod$ref[tmod$ref!=""],to=tmod$models[tmod$ref!=""],imp=tmod$imp[tmod$ref!=""],stringsAsFactors = FALSE) diff --git a/inst/Dashboard/app.R b/inst/Dashboard/app.R index 0142293..b1e94f8 100644 --- a/inst/Dashboard/app.R +++ b/inst/Dashboard/app.R @@ -1,3 +1,5 @@ +this_wd <- getwd() + # Loading libraries library(shiny) # Used as it is a shiny app library(bs4Dash) # Used instead of shinydashboard to provide additional options @@ -13,7 +15,7 @@ if ("nlmixr2" %in% rownames(installed.packages())){ } # Initiate project -proj_obj <- get_proj() +proj_obj <- get_proj(this_wd) # Create theme for dashboard newtheme <- create_theme( @@ -74,7 +76,8 @@ server <- function(input, output, session) { # Top-level reactive values r <- reactiveValues(active_tab = "", model_updated = 0, - proj_obj = get_proj()) + proj_obj = get_proj(this_wd), + this_wd = this_wd) observeEvent(input$tabs, r$active_tab <- input$tabs) From ec607b92bd214d76a1f36bba5bb598b964271652 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 16 Apr 2024 14:28:09 +0200 Subject: [PATCH 08/41] get proj from correct location --- R/module_partable.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/module_partable.R b/R/module_partable.R index 4865f2a..1b4adcf 100644 --- a/R/module_partable.R +++ b/R/module_partable.R @@ -43,13 +43,13 @@ module_pt_server <- function(id, r) { },ignoreInit=TRUE) # Create parameter table - parTable <- function(inp,projloc=".",saveit=FALSE){ - obj <- get_proj(projloc=projloc) - if(!saveit){ + parTable <- function(inp, projloc, saveit = FALSE){ + obj <- get_proj(projloc = projloc) + if(!saveit) { #print(obj) #print(inp$EstLst) par_table(obj,models=inp$EstLst,bsv=inp$bsv,shrink=inp$shrink,backt=inp$backt,formatting=TRUE) - }else{ + } else { savnm <- ifelse(inp$typePars=="PDF",paste0(inp$namePars,".tex"),paste0(inp$namePars,".html")) #print(savnm) par_table(obj,models=inp$EstLst,outnm=savnm,show=inp$showPars,projloc=projloc,bsv=inp$bsv,shrink=inp$shrink,backt=inp$backt,formatting=ifelse(inp$typePars=="PDF",FALSE,TRUE)) @@ -60,7 +60,7 @@ module_pt_server <- function(id, r) { req(r$model_updated) - table <- parTable(input) + table <- parTable(input, projloc = r$this_wd) r$params <- table DT::datatable( @@ -91,6 +91,6 @@ module_pt_server <- function(id, r) { ) } observeEvent(input$savePars,showModal(parsave())) - observeEvent(input$savePars2, parTable(input,saveit=TRUE)) + observeEvent(input$savePars2, parTable(input, projloc = r$this_wd, saveit = TRUE)) }) } From 05a6b683d5cb5bf8beaf2b020f6782025e4a99ae Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 16 Apr 2024 15:33:38 +0200 Subject: [PATCH 09/41] formatting --- R/run_nmx.r | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/R/run_nmx.r b/R/run_nmx.r index 4e5ba5a..1eae6cc 100644 --- a/R/run_nmx.r +++ b/R/run_nmx.r @@ -51,8 +51,17 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= tmpl <- readLines(paste0(system.file(package = "shinyMixR"),"/Other/run_nmx.tmp")) if(is.null(meta$subs)) subs <- "" else subs <- meta$subs - rlst <- list(modelloc=normalizePath(proj[[mod]]$model,winslash = "/",mustWork = FALSE), data=meta$data, subs=subs, - est=meta$est, control=cntrll, saveres=saverds, modelname=mod,locproj=projloc,addcwres=addcwres,addnpde=addnpde) + + rlst <- list(modelloc=normalizePath(proj[[mod]]$model,winslash = "/",mustWork = FALSE), + data=meta$data, + subs=subs, + est=meta$est, + control=cntrll, + saveres=saverds, + modelname=mod, + locproj=projloc, + addcwres=addcwres, + addnpde=addnpde) tscr <- paste0(projloc,"/shinyMixR/temp/script.",stringi::stri_rand_strings(1,6),".r") writeLines(whisker::whisker.render(tmpl,rlst),tscr) From edc9507cdb9952bfaa16edcc68c445b4bb4953a8 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 17 Apr 2024 16:09:47 +0200 Subject: [PATCH 10/41] change paths + update object after model run --- R/get_proj.r | 10 +++++----- R/module_run.R | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/R/get_proj.r b/R/get_proj.r index df61e21..6062d31 100644 --- a/R/get_proj.r +++ b/R/get_proj.r @@ -14,15 +14,15 @@ #' proj <- get_proj() #' } get_proj <- function(projloc=".",geteval=TRUE){ - + # Read in models and place in result objects dir.create(paste0(projloc,"/shinyMixR"),showWarnings = FALSE,recursive = TRUE) mdln <- normalizePath(list.files(paste0(projloc,"/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE)) mdlnb <- sub("\\.[r|R]","",basename(mdln)) - sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE)) + sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE)) sumresi <- file.info(sumres) summdli <- file.info(mdln) - + # read in data folder (only in case objects are not yet present) datf <- list.files(paste0(projloc,"/data")) grepd <- " |^[[:digit:]]|\\!|\\#|\\$|\\%|\\&|\\'|\\(|\\)|\\-|\\;|\\=|\\@|\\[|\\]|\\^\\`\\{\\|\\}" @@ -36,7 +36,7 @@ get_proj <- function(projloc=".",geteval=TRUE){ }) # Read in models and results - if(!file.exists(paste0(projloc,"/shinyMixR/project.rds"))){ + if(!file.exists(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds"))){ mdls <- lapply(mdln,list) names(mdls) <- sub("\\.[r|R]","",basename(mdln)) if(length(mdln)==0){ @@ -52,7 +52,7 @@ get_proj <- function(projloc=".",geteval=TRUE){ for(i in sumres) mdls[[sub("\\.ressum\\.rds","",basename(i))]]$results <- readRDS(i) mdls$meta <- list(lastrefresh=Sys.time()) }else{ - mdls <- readRDS(paste0(projloc,"/shinyMixR/project.rds")) + mdls <- readRDS(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds")) # for the list with models, check if new models are available or old models are deleted # and if models are updated after last refresh: # inproj <- unlist(sapply(mdls[names(mdls)[names(mdls)!="meta"]],"[",1)) diff --git a/R/module_run.R b/R/module_run.R index 135309f..4e4c06b 100644 --- a/R/module_run.R +++ b/R/module_run.R @@ -56,7 +56,7 @@ module_run_server <- function(id, r) { myalert("model(s) submitted, wait for progress log to pop-up!",type = "succes") addcwres <- ifelse("Add CWRES to output"%in%input$addExtra,TRUE,FALSE) addnpde <- ifelse("Add NPDE to output"%in%input$addExtra,TRUE,FALSE) - lapply(input$runLst,function(mods) run_nmx(mods,r$proj_obj,addcwres=addcwres,addnpde=addnpde)) + lapply(input$runLst,function(mods) run_nmx(mods, r$proj_obj, addcwres=addcwres,addnpde=addnpde)) } }else{ myalert("Please select models to run",type = "error") @@ -81,6 +81,7 @@ module_run_server <- function(id, r) { # check if "run finished" prevails in runmodmonit() if(grepl("run finished", runmodmonit())){ r$model_updated <- isolate(r$model_updated) + 1 + r$proj_obj <- get_proj(r$this_wd) } }) From e5d336ff4a2eb6f87d5b220e24b54a22bd70d61a Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 17 Apr 2024 16:35:17 +0200 Subject: [PATCH 11/41] move creation of temp folder to run_shinymixr --- R/module_overview.R | 2 -- R/run_shinymixr.r | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/R/module_overview.R b/R/module_overview.R index 1ba2ecf..9b2e710 100644 --- a/R/module_overview.R +++ b/R/module_overview.R @@ -120,8 +120,6 @@ module_overview_server <- function(id, r) { } },ignoreInit = TRUE) - # Running scripts - Check creation of temp folder (should be done in create_proj (get_proj) function?) - dir.create("shinyMixR/temp",showWarnings = FALSE,recursive = TRUE) module_scripts_server("runscripts", files = reactive(r$mdls), scripts = reactive(r$scrpt), loc = "shinyMixR/temp") # Creating reports diff --git a/R/run_shinymixr.r b/R/run_shinymixr.r index 74584fd..29ba971 100644 --- a/R/run_shinymixr.r +++ b/R/run_shinymixr.r @@ -17,7 +17,7 @@ run_shinymixr <- function(wd = getwd(), dry_run = FALSE, ...){ if(!file.exists(paste0(wd,"/shinyMixR/app/www"))) try(dir.create(paste0(wd,"/shinyMixR/app/www"),recursive = TRUE)) - if(!file.exists(paste0(wd,"/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/temp"),recursive=TRUE)) + if(!file.exists(paste0(wd,"/shinyMixR/app/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/app/shinyMixR/temp"),recursive=TRUE)) try(file.copy(system.file("Dashboard","app.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/app.R"),overwrite = TRUE),silent = TRUE) try(file.copy(system.file("Dashboard","www/logoshinyMixR.png",package="shinyMixR"), paste0(wd,"/shinyMixR/app/www/logoshinyMixR.png")),silent = TRUE) From 5c65439e1cfb8b0f8df3cd8ce4636c7f8e1b7e70 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 17 Apr 2024 16:35:31 +0200 Subject: [PATCH 12/41] change file path --- R/get_proj.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/get_proj.r b/R/get_proj.r index 6062d31..55fdbef 100644 --- a/R/get_proj.r +++ b/R/get_proj.r @@ -92,6 +92,6 @@ get_proj <- function(projloc=".",geteval=TRUE){ chk <- chk[which(chk$mdlsv>chk$ressv),] #if(nrow(chk)>0) noret <- apply(chk,1,function(x) cat("Be aware that model is saved after results for",x['mdl'],"\n")) - saveRDS(mdls,file=paste0(projloc,"/shinyMixR/project.rds")) + saveRDS(mdls,file=paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds")) return(mdls) } From 1902e77946fa54725eccfca80ac9bc03db3f30e0 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 23 Apr 2024 15:45:20 +0200 Subject: [PATCH 13/41] remove nlmixr + bump version --- DESCRIPTION | 8 ++++---- NEWS.md | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 68589ea..4118028 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,14 +1,14 @@ Package: shinyMixR -Title: Shiny dashboard interface for nlmixr and nlmixr2 -Version: 0.4.0 +Title: Interactive 'shiny' Dashboard for 'nlmixr2' +Version: 0.5.0 Authors@R: c(person("Richard", "Hooijmaijers", email = "richardhooijmaijers@gmail.com", role = c("aut", "cre","cph")), person("Teun", "Post", email = "teunpost@gmail.com",role = c("aut","cph")), person("LAPP Consultants",email = "info@lapp.nl", role=c("fnd","cph")), person("Matthew Fidler",role=c("ctb"))) Author: Richard Hooijmaijers Maintainer: Richard Hooijmaijers -Description: The package is developed as an interface for the nlmixr and nlmixr2 package. Furthermore additional functions - are included to work with the nlmixr package through the command line +Description: An interface for the 'nlmixr2' package. Furthermore additional functions + are included to work with the 'nlmixr2' package through the command line. Depends: R (>= 3.5.0), shiny, diff --git a/NEWS.md b/NEWS.md index 6a95013..6871514 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# shinyMixR 0.5 + +This version is a preview version of the package. The main changes are: + +- Refactoring of the code to remove global assignments and implement use of reactiveValues. +- Added codecoverage to the package. +- Added a new testing structure to the package including `shinytest2` for automated testing of the app. +- Improved documentation to prepare for CRAN submission. + # shinyMixR 0.4 Within this version some updates have been implemented, see below the most important changes: From 617cc83f0ee25f0ff85e2c5967aae23309e52eac Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 23 Apr 2024 15:45:46 +0200 Subject: [PATCH 14/41] docs: proj_obj --- man/overview.Rd | 6 ++++-- man/tree_overview.Rd | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/man/overview.Rd b/man/overview.Rd index fa43cf4..ca530fb 100644 --- a/man/overview.Rd +++ b/man/overview.Rd @@ -4,9 +4,11 @@ \alias{overview} \title{Creates model overview} \usage{ -overview(...) +overview(proj_obj, ...) } \arguments{ +\item{proj_obj}{a project object created with \code{\link{get_proj}}} + \item{...}{additional arguments passed to \code{\link{get_proj}}} } \value{ @@ -19,7 +21,7 @@ of the models and if results are available, also the objective function and run- \examples{ \dontrun{ - overview() + overview(proj_obj) } } \author{ diff --git a/man/tree_overview.Rd b/man/tree_overview.Rd index ca06772..6c14112 100644 --- a/man/tree_overview.Rd +++ b/man/tree_overview.Rd @@ -4,9 +4,11 @@ \alias{tree_overview} \title{Creates tree overview of models} \usage{ -tree_overview(...) +tree_overview(proj_obj, ...) } \arguments{ +\item{proj_obj}{a project object created with \code{\link{get_proj}}} + \item{...}{additional arguments passed to \code{\link{overview}}} } \value{ @@ -20,7 +22,7 @@ visualise the relationship between models \examples{ \dontrun{ - tree_overview() + tree_overview(proj_obj) } } \seealso{ From 1f767587e2f24704271e2acf656a656a8d489ccb Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 23 Apr 2024 15:46:05 +0200 Subject: [PATCH 15/41] declare record_test --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index b98b928..1f2f60b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -31,6 +31,6 @@ setup_shinymixr_test <- function(dir = "./tests/files", overwrite = TRUE, record } if (record == TRUE) { - record_test(paste0(dir, "/shinyMixR/app")) + shinytest2::record_test(paste0(dir, "/shinyMixR/app")) } } From be8acd910186d4be88f7a30b0328530429af07a2 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 23 Apr 2024 16:50:17 +0200 Subject: [PATCH 16/41] very wip: change locations --- R/create_proj.r | 7 ++++++- R/get_proj.r | 10 ++++++---- R/run_nmx.r | 8 ++++---- R/utils.R | 6 ++++-- tests/testthat/test-shinymixr-01-model-run1.R | 4 ++-- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/R/create_proj.r b/R/create_proj.r index ddd8aa9..20f5390 100644 --- a/R/create_proj.r +++ b/R/create_proj.r @@ -16,8 +16,13 @@ #' create_proj() #' } create_proj <- function(loc=".", overwrite=FALSE){ + + loc <- paste0(loc, "/shinyMixR/app") + + if(!dir.exists(loc)) dir.create(loc, recursive = TRUE) + # First create the folder structure - dirs <- paste0(loc,c("/analysis","/data","/models","/shinyMixR","/scripts")) + dirs <- paste0(loc, c("/analysis","/data","/models","/shinyMixR","/scripts")) if(!all(dirs%in%list.files(loc,full.names = TRUE))){ sapply(dirs,dir.create,showWarnings = FALSE,recursive=TRUE) # Now place in some default models and data diff --git a/R/get_proj.r b/R/get_proj.r index 55fdbef..943b6f8 100644 --- a/R/get_proj.r +++ b/R/get_proj.r @@ -15,20 +15,22 @@ #' } get_proj <- function(projloc=".",geteval=TRUE){ + print(projloc) + # Read in models and place in result objects - dir.create(paste0(projloc,"/shinyMixR"),showWarnings = FALSE,recursive = TRUE) - mdln <- normalizePath(list.files(paste0(projloc,"/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE)) + dir.create(paste0(projloc,"/shinyMixR/app/shinyMixR"),showWarnings = FALSE,recursive = TRUE) + mdln <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE)) mdlnb <- sub("\\.[r|R]","",basename(mdln)) sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE)) sumresi <- file.info(sumres) summdli <- file.info(mdln) # read in data folder (only in case objects are not yet present) - datf <- list.files(paste0(projloc,"/data")) + datf <- list.files(paste0(projloc,"/shinyMixR/app/data")) grepd <- " |^[[:digit:]]|\\!|\\#|\\$|\\%|\\&|\\'|\\(|\\)|\\-|\\;|\\=|\\@|\\[|\\]|\\^\\`\\{\\|\\}" if(any(grepl(grepd,datf))) warning("Data files with special characters found, take into acount that models that use these can crash") # not relevant to read all data for running nlmixr in separate session (should be loaded in this session!) - lapply(list.files(paste0(projloc,"/data"),full.names = TRUE),function(x){ + lapply(list.files(paste0(projloc,"/shinyMixR/app/data"),full.names = TRUE),function(x){ if(!grepl(grepd,x) & !exists(sub("\\.rds$|\\.csv$","",basename(x),ignore.case = TRUE),envir=.GlobalEnv)){ if(grepl("\\.rds$",x,ignore.case = TRUE)) assign(sub("\\.rds$","",basename(x),ignore.case = TRUE),readRDS(x),pos = .GlobalEnv) if(grepl("\\.csv$",x,ignore.case = TRUE)) assign(sub("\\.csv$","",basename(x),ignore.case = TRUE),read.csv(x),pos = .GlobalEnv) diff --git a/R/run_nmx.r b/R/run_nmx.r index 1eae6cc..cd21570 100644 --- a/R/run_nmx.r +++ b/R/run_nmx.r @@ -28,8 +28,8 @@ #' } run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc=".",addcwres=TRUE,addnpde=TRUE){ - dnm <- deparse(substitute(proj)) - if(autoupdate) assign(dnm,get_proj(projloc=projloc)) + # dnm <- deparse(substitute(proj)) + # if(autoupdate) assign(dnm,get_proj(projloc=projloc)) # Source model to obtain meta data (places meta object in env) sret <- try(source(proj[[mod]]$model,local=TRUE)) meta <- try(eval(parse(text=c("nlmixr(",readLines(proj[[mod]]$model),")$meta")))) @@ -72,7 +72,7 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= system(paste0(R.home("bin"), "/Rscript \"", tscr, "\" > \"",projloc,"/shinyMixR/temp/",mod,".prog.txt\" 2>&1"),wait=FALSE) } - if(autoupdate) assign(dnm,proj,pos = .GlobalEnv) + # if(autoupdate) assign(dnm,proj,pos = .GlobalEnv) }else{ # Handle subsetting (data is loaded in global environment by get_proj function) if(!is.null(meta$subs) && meta$subs!="") data_nlm <- subset(get(meta$data),eval(parse(text=(meta$subs)))) else data_nlm <- get(meta$data) @@ -87,7 +87,7 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= saveRDS(ressum,file=paste0(projloc,"/shinyMixR/",mod,".ressum.rds")) } proj[[mod]]$results <- ressum - assign(dnm,proj,pos = .GlobalEnv) + # assign(dnm,proj,pos = .GlobalEnv) return(modres) } } diff --git a/R/utils.R b/R/utils.R index 1f2f60b..65bac90 100644 --- a/R/utils.R +++ b/R/utils.R @@ -19,10 +19,12 @@ setup_shinymixr_test <- function(dir = "./tests/files", overwrite = TRUE, record } create_proj(dir, overwrite = overwrite) + run_shinymixr(wd = dir, dry_run = TRUE) + if(incres){ - file.copy(system.file(c("Other/run1.res.rds","Other/run1.ressum.rds"),package="shinyMixR"),paste0(dir,"/shinyMixR")) + file.copy(system.file(c("Other/run1.res.rds","Other/run1.ressum.rds"),package="shinyMixR"), + paste0(dir,"/shinyMixR/app/shinyMixR")) } - run_shinymixr(wd = dir, dry_run = TRUE) # create .Rprofile file to store settings if (!file.exists(paste0(dir, "/.Rprofile"))) { diff --git a/tests/testthat/test-shinymixr-01-model-run1.R b/tests/testthat/test-shinymixr-01-model-run1.R index dbc3199..819e77d 100644 --- a/tests/testthat/test-shinymixr-01-model-run1.R +++ b/tests/testthat/test-shinymixr-01-model-run1.R @@ -29,10 +29,10 @@ test_that("Shiny app runs model and returns parameters for run1", { # Test if run is done and 'correct' results have been created Sys.sleep(1) - rundone <- "run1.res.rds"%in%list.files(paste0(tempdir(),"/files/shinyMixR")) + rundone <- "run1.res.rds"%in%list.files(paste0(tempdir(),"/files/shinyMixR/app/shinyMixR")) expect_true(rundone) if(rundone){ - runres <- readRDS(paste0(tempdir(),"/files/shinyMixR/run1.res.rds")) + runres <- readRDS(paste0(tempdir(),"/files/shinyMixR/app/shinyMixR/run1.res.rds")) expect_true(inherits(runres,"nlmixr2FitData")) } From 778b983d0de9fa5effb38a258cd46e4e028bf76d Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 08:24:24 +0200 Subject: [PATCH 17/41] point to correct folder --- tests/testthat/test-shinymixr-03-create-newmodel.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-shinymixr-03-create-newmodel.R b/tests/testthat/test-shinymixr-03-create-newmodel.R index 34a4dad..708d68e 100644 --- a/tests/testthat/test-shinymixr-03-create-newmodel.R +++ b/tests/testthat/test-shinymixr-03-create-newmodel.R @@ -32,10 +32,10 @@ test_that("Shiny app correctly creates new model code", { app$expect_values(input = "editor-newgo") # Check if new model is created and contains correct naming - modmade <- "run2.r" %in% list.files(paste0(temp_dir, "/files/models")) + modmade <- "run2.r" %in% list.files(paste0(temp_dir, "/files/shinyMixR/app/models")) expect_true(modmade) if(modmade){ - modcont <- readLines(paste0(temp_dir, "/files/models/run2.r")) + modcont <- readLines(paste0(temp_dir, "/files/shinyMixR/app/models/run2.r")) expect_true(grepl("run2 <- function", modcont[1])) } @@ -49,7 +49,7 @@ test_that("Shiny app correctly creates new model code", { expect_true(curvals$input$`editor-adapt_meta_ed-mdlimp`==1) app$click("editor-adapt_meta_ed-adpt") app$click(selector = ".swal2-confirm") - expect_true("run3.r"%in%list.files(paste0(tempdir(),"/files/models"))) + expect_true("run3.r"%in%list.files(paste0(tempdir(),"/files/shinyMixR/app/models"))) # Finally test if update inits works as expected (e.g. are initial changed, values itself tested outside shinytest) app$click("editor-updinit") From b88889323d67083349066e2e160a44b3f2f025f7 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 09:01:29 +0200 Subject: [PATCH 18/41] fix LICENSE warning --- .Rbuildignore | 3 +++ DESCRIPTION | 2 +- LICENSE.md | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 LICENSE.md diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..3056e71 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,5 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +^\.github$ +^\.vscode$ +^LICENSE\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index 4118028..b13ec0e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,7 +37,7 @@ Suggests: knitr, rmarkdown, rlang -License: MIT+LICENSE +License: MIT + file LICENSE Encoding: UTF-8 LazyData: true RoxygenNote: 7.2.3 diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..12fb21d --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2024 shinyMixR authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From a8486470513597f1ba7a1add57241999acd1cc65 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 09:06:38 +0200 Subject: [PATCH 19/41] move non standard directories to /inst --- R/create_proj.r | 10 +++++----- R/module_edit.R | 2 +- R/run_nmx.r | 2 +- R/run_shinymixr.r | 6 +++--- R/utils.R | 2 +- .../cheatsheet}/CheatSheet_shinymixr.pdf | Bin {installation => inst/installation}/install_fun.r | 0 {shortcuts => inst/shortcuts}/README.md | 0 .../shortcuts}/start_shinyMixR_Lin.sh | 0 .../shortcuts}/start_shinyMixR_Mac.command | 0 .../shortcuts}/start_shinyMixR_Win10.bat | 0 .../shortcuts}/start_shinyMixR_Win7.bat | 0 tests/testthat/test-gof_plot.R | 2 +- vignettes/getting_started.Rmd | 2 +- 14 files changed, 13 insertions(+), 13 deletions(-) rename {cheatsheet => inst/cheatsheet}/CheatSheet_shinymixr.pdf (100%) rename {installation => inst/installation}/install_fun.r (100%) rename {shortcuts => inst/shortcuts}/README.md (100%) rename {shortcuts => inst/shortcuts}/start_shinyMixR_Lin.sh (100%) rename {shortcuts => inst/shortcuts}/start_shinyMixR_Mac.command (100%) rename {shortcuts => inst/shortcuts}/start_shinyMixR_Win10.bat (100%) rename {shortcuts => inst/shortcuts}/start_shinyMixR_Win7.bat (100%) diff --git a/R/create_proj.r b/R/create_proj.r index 20f5390..ecdede9 100644 --- a/R/create_proj.r +++ b/R/create_proj.r @@ -26,10 +26,10 @@ create_proj <- function(loc=".", overwrite=FALSE){ if(!all(dirs%in%list.files(loc,full.names = TRUE))){ sapply(dirs,dir.create,showWarnings = FALSE,recursive=TRUE) # Now place in some default models and data - if(!file.exists(paste0(loc,"/models/run1.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/run1.r"),paste0(loc,"/models/run1.r")) - if(!file.exists(paste0(loc,"/data/theo_sd.rds")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/theo_sd.rds"),paste0(loc,"/data/theo_sd.rds")) - if(!file.exists(paste0(loc,"/scripts/eta.plot.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/eta.plot.r"),paste0(loc,"/scripts/eta.plot.r")) - if(!file.exists(paste0(loc,"/scripts/vpc.plot.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/vpc.plot.r"),paste0(loc,"/scripts/vpc.plot.r")) - if(!file.exists(paste0(loc,"/scripts/combined.results.html.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/Other/combined.results.html.r"),paste0(loc,"/scripts/combined.results.html.r")) + if(!file.exists(paste0(loc,"/models/run1.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/run1.r"),paste0(loc,"/models/run1.r")) + if(!file.exists(paste0(loc,"/data/theo_sd.rds")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/theo_sd.rds"),paste0(loc,"/data/theo_sd.rds")) + if(!file.exists(paste0(loc,"/scripts/eta.plot.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/eta.plot.r"),paste0(loc,"/scripts/eta.plot.r")) + if(!file.exists(paste0(loc,"/scripts/vpc.plot.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/vpc.plot.r"),paste0(loc,"/scripts/vpc.plot.r")) + if(!file.exists(paste0(loc,"/scripts/combined.results.html.r")) | overwrite) file.copy(paste0(system.file(package = "shinyMixR"),"/other/combined.results.html.r"),paste0(loc,"/scripts/combined.results.html.r")) } } diff --git a/R/module_edit.R b/R/module_edit.R index 29b932a..e16dbd1 100644 --- a/R/module_edit.R +++ b/R/module_edit.R @@ -59,7 +59,7 @@ module_edit_server <- function(id, r, settings) { showModal(newmodmodal()) },ignoreInit=TRUE) observeEvent(input$newgo,{ - mdl <- try(readLines(system.file(paste0("Other/",input$templnew,".r"),package="shinyMixR"))) + mdl <- try(readLines(system.file(paste0("other/",input$templnew,".r"),package="shinyMixR"))) if(!"try-error"%in%class(mdl)){ mdl <- sub("run1",sub("\\.[r|R]","",input$namenew),mdl) writeLines(mdl,paste0("models/",input$namenew)) diff --git a/R/run_nmx.r b/R/run_nmx.r index cd21570..9808639 100644 --- a/R/run_nmx.r +++ b/R/run_nmx.r @@ -49,7 +49,7 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= cntrla <- grepl("^control *=|^control.*<-",cntrll) if(any(cntrla)){cntrll <- gsub("^control *=|^control.*<-","",cntrll[cntrla])}else{cntrll <- "list()"} - tmpl <- readLines(paste0(system.file(package = "shinyMixR"),"/Other/run_nmx.tmp")) + tmpl <- readLines(paste0(system.file(package = "shinyMixR"),"/other/run_nmx.tmp")) if(is.null(meta$subs)) subs <- "" else subs <- meta$subs rlst <- list(modelloc=normalizePath(proj[[mod]]$model,winslash = "/",mustWork = FALSE), diff --git a/R/run_shinymixr.r b/R/run_shinymixr.r index 29ba971..ddff5b7 100644 --- a/R/run_shinymixr.r +++ b/R/run_shinymixr.r @@ -19,11 +19,11 @@ run_shinymixr <- function(wd = getwd(), dry_run = FALSE, ...){ if(!file.exists(paste0(wd,"/shinyMixR/app/www"))) try(dir.create(paste0(wd,"/shinyMixR/app/www"),recursive = TRUE)) if(!file.exists(paste0(wd,"/shinyMixR/app/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/app/shinyMixR/temp"),recursive=TRUE)) - try(file.copy(system.file("Dashboard","app.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/app.R"),overwrite = TRUE),silent = TRUE) - try(file.copy(system.file("Dashboard","www/logoshinyMixR.png",package="shinyMixR"), paste0(wd,"/shinyMixR/app/www/logoshinyMixR.png")),silent = TRUE) + try(file.copy(system.file("dashboard","app.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/app.R"),overwrite = TRUE),silent = TRUE) + try(file.copy(system.file("dashboard","www/logoshinyMixR.png",package="shinyMixR"), paste0(wd,"/shinyMixR/app/www/logoshinyMixR.png")),silent = TRUE) # Set the working directory so the project can be found - adpt <- readLines(system.file("Dashboard", "app.R", package = "shinyMixR")) + adpt <- readLines(system.file("dashboard", "app.R", package = "shinyMixR")) adpt <- c(paste0("setwd(\"", normalizePath(wd, winslash = "/"), "\")"), adpt) writeLines(adpt, paste0(wd,"/shinyMixR/app/app.R")) diff --git a/R/utils.R b/R/utils.R index 65bac90..db6efa3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -22,7 +22,7 @@ setup_shinymixr_test <- function(dir = "./tests/files", overwrite = TRUE, record run_shinymixr(wd = dir, dry_run = TRUE) if(incres){ - file.copy(system.file(c("Other/run1.res.rds","Other/run1.ressum.rds"),package="shinyMixR"), + file.copy(system.file(c("other/run1.res.rds","other/run1.ressum.rds"),package="shinyMixR"), paste0(dir,"/shinyMixR/app/shinyMixR")) } diff --git a/cheatsheet/CheatSheet_shinymixr.pdf b/inst/cheatsheet/CheatSheet_shinymixr.pdf similarity index 100% rename from cheatsheet/CheatSheet_shinymixr.pdf rename to inst/cheatsheet/CheatSheet_shinymixr.pdf diff --git a/installation/install_fun.r b/inst/installation/install_fun.r similarity index 100% rename from installation/install_fun.r rename to inst/installation/install_fun.r diff --git a/shortcuts/README.md b/inst/shortcuts/README.md similarity index 100% rename from shortcuts/README.md rename to inst/shortcuts/README.md diff --git a/shortcuts/start_shinyMixR_Lin.sh b/inst/shortcuts/start_shinyMixR_Lin.sh similarity index 100% rename from shortcuts/start_shinyMixR_Lin.sh rename to inst/shortcuts/start_shinyMixR_Lin.sh diff --git a/shortcuts/start_shinyMixR_Mac.command b/inst/shortcuts/start_shinyMixR_Mac.command similarity index 100% rename from shortcuts/start_shinyMixR_Mac.command rename to inst/shortcuts/start_shinyMixR_Mac.command diff --git a/shortcuts/start_shinyMixR_Win10.bat b/inst/shortcuts/start_shinyMixR_Win10.bat similarity index 100% rename from shortcuts/start_shinyMixR_Win10.bat rename to inst/shortcuts/start_shinyMixR_Win10.bat diff --git a/shortcuts/start_shinyMixR_Win7.bat b/inst/shortcuts/start_shinyMixR_Win7.bat similarity index 100% rename from shortcuts/start_shinyMixR_Win7.bat rename to inst/shortcuts/start_shinyMixR_Win7.bat diff --git a/tests/testthat/test-gof_plot.R b/tests/testthat/test-gof_plot.R index 6b358ee..1f67723 100644 --- a/tests/testthat/test-gof_plot.R +++ b/tests/testthat/test-gof_plot.R @@ -1,6 +1,6 @@ test_that("gof_plot works as expected", { - res_path <- system.file("/Other/run1.res.rds", package = "shinyMixR") + res_path <- system.file("/other/run1.res.rds", package = "shinyMixR") res <- readRDS(res_path) diff --git a/vignettes/getting_started.Rmd b/vignettes/getting_started.Rmd index 96c29e7..0be2c99 100644 --- a/vignettes/getting_started.Rmd +++ b/vignettes/getting_started.Rmd @@ -216,7 +216,7 @@ par_table(proj_obj, models="run1", outnm="par.tex") For assessing the goodness of fit, the `gof_plot` function can be used. This function will by default use the `nlmixr.xpose2` package to create 4 different types of plots. It is also possible to directly create ggplot2 types of plots. By default the plots will be created within the R session but can also be written to pdf/html using the `R3port` package: ```{r eval=TRUE, echo=FALSE, message=FALSE, warning=FALSE} library(shinyMixR) -res <- readRDS(system.file("Other/run1.res.rds",package="shinyMixR")) +res <- readRDS(system.file("other/run1.res.rds",package="shinyMixR")) ``` ```{r eval=FALSE, echo=TRUE} res <- readRDS("./shinyMixR/run1.res.rds") From d2bedc222fc862d04d16f6efaba4a41a19502587 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 09:11:23 +0200 Subject: [PATCH 20/41] add pkgdown files --- .Rbuildignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 3056e71..e79996c 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,3 +3,6 @@ ^\.github$ ^\.vscode$ ^LICENSE\.md$ +^_pkgdown\.yml$ +^pkgdown$ +^docs$ From 5e3061c828372504940cb5b73c8e62b814bd20c3 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 09:21:44 +0200 Subject: [PATCH 21/41] fix found if() conditions comparing class() to string --- R/overview.r | 2 +- R/run_nmx.r | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/overview.r b/R/overview.r index c36ac2f..51eb4a7 100644 --- a/R/overview.r +++ b/R/overview.r @@ -18,7 +18,7 @@ overview <- function(proj_obj, ...){ mdln <- names(proj_obj)[names(proj_obj)!="meta"] res1 <- lapply(mdln, function(x){ - if(class(proj_obj[[x]]$modeleval)=="try-error" || class(proj_obj[[x]]$modeleval$meta)=="try-error"){ + if(inherits(proj_obj[[x]]$modeleval, "try-error") || inherits(proj_obj[[x]]$modeleval$meta, "try-error")){ c(NA,"","","","") }else{ meta <- proj_obj[[x]]$modeleval$meta diff --git a/R/run_nmx.r b/R/run_nmx.r index 9808639..a397735 100644 --- a/R/run_nmx.r +++ b/R/run_nmx.r @@ -33,7 +33,7 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= # Source model to obtain meta data (places meta object in env) sret <- try(source(proj[[mod]]$model,local=TRUE)) meta <- try(eval(parse(text=c("nlmixr(",readLines(proj[[mod]]$model),")$meta")))) - if(class(meta)=="try-error" || class(sret)=="try-error"){ + if(inherits(meta, "try-error") || inherits(sret, "try-error")){ cat("Error in model syntax please check before running\n") if(ext) writeLines(meta, paste0(projloc,"/shinyMixR/temp/",mod,".prog.txt")) return() From 24f3209e0c73eccaa9658fd71c3f768c734cc294 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 10:17:40 +0200 Subject: [PATCH 22/41] import magrittr, stats, utils --- DESCRIPTION | 3 ++- NAMESPACE | 7 +++++++ R/shinyMixR-package.R | 9 +++++++++ man/shinyMixR-package.Rd | 26 ++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 R/shinyMixR-package.R create mode 100644 man/shinyMixR-package.Rd diff --git a/DESCRIPTION b/DESCRIPTION index b13ec0e..ef6dd8c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,8 @@ Description: An interface for the 'nlmixr2' package. Furthermore additional func Depends: R (>= 3.5.0), shiny, - ggplot2 + ggplot2, + magrittr Imports: gridExtra, collapsibleTree, diff --git a/NAMESPACE b/NAMESPACE index f5ca749..2a9a6eb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -42,4 +42,11 @@ export(update_inits) import(bs4Dash) import(ggplot2) import(gridExtra) +importFrom(magrittr,"%>%") importFrom(shiny,runApp) +importFrom(stats,na.omit) +importFrom(stats,setNames) +importFrom(utils,getParseData) +importFrom(utils,installed.packages) +importFrom(utils,read.csv) +importFrom(utils,tail) diff --git a/R/shinyMixR-package.R b/R/shinyMixR-package.R new file mode 100644 index 0000000..c09a29b --- /dev/null +++ b/R/shinyMixR-package.R @@ -0,0 +1,9 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +#' @importFrom stats na.omit setNames +#' @importFrom utils getParseData installed.packages read.csv tail +#' @importFrom magrittr "%>%" +## usethis namespace: end +NULL \ No newline at end of file diff --git a/man/shinyMixR-package.Rd b/man/shinyMixR-package.Rd new file mode 100644 index 0000000..3ee053c --- /dev/null +++ b/man/shinyMixR-package.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/shinyMixR-package.R +\docType{package} +\name{shinyMixR-package} +\alias{shinyMixR} +\alias{shinyMixR-package} +\title{shinyMixR: Interactive 'shiny' Dashboard for 'nlmixr2'} +\description{ +An interface for the 'nlmixr2' package. Furthermore additional functions are included to work with the 'nlmixr2' package through the command line. +} +\author{ +\strong{Maintainer}: Richard Hooijmaijers \email{richardhooijmaijers@gmail.com} [copyright holder] + +Authors: +\itemize{ + \item Teun Post \email{teunpost@gmail.com} [copyright holder] +} + +Other contributors: +\itemize{ + \item LAPP Consultants \email{info@lapp.nl} [funder, copyright holder] + \item Matthew Fidler [contributor] +} + +} +\keyword{internal} From c8ed35cf5aca4b93507bb7c58d18fa6558c8e060 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 10:18:03 +0200 Subject: [PATCH 23/41] change location of exportTestValues --- R/module_run.R | 7 +++---- tests/testthat/test-shinymixr-01-model-run1.R | 4 ++-- vignettes/getting_started.Rmd | 5 ++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/R/module_run.R b/R/module_run.R index 4e4c06b..aecb8dd 100644 --- a/R/module_run.R +++ b/R/module_run.R @@ -82,13 +82,12 @@ module_run_server <- function(id, r) { if(grepl("run finished", runmodmonit())){ r$model_updated <- isolate(r$model_updated) + 1 r$proj_obj <- get_proj(r$this_wd) + exportTestValues( + model_updated = r$model_updated + ) } }) - exportTestValues( - model_updated = r$model_updated - ) - output$progrTxt <- renderText(runmodmonit()) # Monitor all external runs rv <- reactiveValues(montbl=NULL) diff --git a/tests/testthat/test-shinymixr-01-model-run1.R b/tests/testthat/test-shinymixr-01-model-run1.R index 819e77d..9798746 100644 --- a/tests/testthat/test-shinymixr-01-model-run1.R +++ b/tests/testthat/test-shinymixr-01-model-run1.R @@ -22,9 +22,9 @@ test_that("Shiny app runs model and returns parameters for run1", { Sys.sleep(1) app$click(selector = ".swal2-confirm") - # Wait for model to finish (0 is the initial value, so we ignore it) + # Wait for model to finish (NULL or 0 is the initial value, so we ignore it) app$wait_for_value(export = "modrun-model_updated", - ignore = 0, + ignore = list(NULL, 0), timeout = 120000) # Test if run is done and 'correct' results have been created diff --git a/vignettes/getting_started.Rmd b/vignettes/getting_started.Rmd index 0be2c99..038d17d 100644 --- a/vignettes/getting_started.Rmd +++ b/vignettes/getting_started.Rmd @@ -214,13 +214,16 @@ par_table(proj_obj, models="run1", outnm="par.tex") ``` For assessing the goodness of fit, the `gof_plot` function can be used. This function will by default use the `nlmixr.xpose2` package to create 4 different types of plots. It is also possible to directly create ggplot2 types of plots. By default the plots will be created within the R session but can also be written to pdf/html using the `R3port` package: + ```{r eval=TRUE, echo=FALSE, message=FALSE, warning=FALSE} library(shinyMixR) -res <- readRDS(system.file("other/run1.res.rds",package="shinyMixR")) +res <- readRDS(system.file("other/run1.res.rds", package = "shinyMixR")) ``` + ```{r eval=FALSE, echo=TRUE} res <- readRDS("./shinyMixR/run1.res.rds") ``` + ```{r message=FALSE, warning=FALSE} gof_plot(res) # gof_plot(res, mdlnm="run1", outnm="gof.tex") From 2550f3120cd4ffd2ecd35d5c409d8dcdf9df45ce Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 10:39:33 +0200 Subject: [PATCH 24/41] debug test --- tests/testthat/test-gof_plot.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-gof_plot.R b/tests/testthat/test-gof_plot.R index 1f67723..9e8d0e9 100644 --- a/tests/testthat/test-gof_plot.R +++ b/tests/testthat/test-gof_plot.R @@ -1,5 +1,7 @@ test_that("gof_plot works as expected", { + print(.libPaths()) + res_path <- system.file("/other/run1.res.rds", package = "shinyMixR") res <- readRDS(res_path) From c26e8f7a5cdaa91d5e4195f54f85ee6c231e9280 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 11:10:42 +0200 Subject: [PATCH 25/41] remove unused code (inputlist$attrl is always FALSE) --- R/exploreplot.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/exploreplot.r b/R/exploreplot.r index 924926d..1889e5e 100644 --- a/R/exploreplot.r +++ b/R/exploreplot.r @@ -27,7 +27,7 @@ exploreplot <- function(inputlist){ # take into account that colour is used to map colour/fill and shape is used to map shape and linetype inputlist$attrl <- FALSE - if(inputlist$attrl==TRUE) {ggstr <- "dataIn <- assign_attr(dataIn,attrl)"}else{ggstr <- NULL} # paste(ggstr,"+\n ",lay1) + ggstr <- NULL if(inputlist$subset=="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(dataIn)") if(inputlist$subset=="" & inputlist$nondups!="") ggstr <- paste0(ggstr,"\n","ggplot(subset(dataIn, !duplicated(",inputlist$nondups,")))") if(inputlist$subset!="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(subset(dataIn,",inputlist$subset,"))") From 484804474332d492aaf1b3514b18385b90a2f4a7 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 11:11:11 +0200 Subject: [PATCH 26/41] explicitly declare imports from shiny and nlmixr2 --- NAMESPACE | 47 +++++++++++++++++++++++++++++++++++++++++++++++ R/run_nmx.r | 2 +- R/run_shinymixr.r | 10 +++++++++- R/update_inits.r | 4 ++-- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 2a9a6eb..a522d1f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -43,7 +43,54 @@ import(bs4Dash) import(ggplot2) import(gridExtra) importFrom(magrittr,"%>%") +importFrom(shiny,HTML) +importFrom(shiny,NS) +importFrom(shiny,br) +importFrom(shiny,checkboxGroupInput) +importFrom(shiny,checkboxInput) +importFrom(shiny,conditionalPanel) +importFrom(shiny,div) +importFrom(shiny,em) +importFrom(shiny,eventReactive) +importFrom(shiny,exportTestValues) +importFrom(shiny,fluidRow) +importFrom(shiny,hr) +importFrom(shiny,icon) +importFrom(shiny,insertUI) +importFrom(shiny,isTruthy) +importFrom(shiny,isolate) +importFrom(shiny,modalDialog) +importFrom(shiny,moduleServer) +importFrom(shiny,numericInput) +importFrom(shiny,observe) +importFrom(shiny,observeEvent) +importFrom(shiny,plotOutput) +importFrom(shiny,radioButtons) +importFrom(shiny,reactive) +importFrom(shiny,reactivePoll) +importFrom(shiny,reactiveVal) +importFrom(shiny,reactiveValues) +importFrom(shiny,reactiveValuesToList) +importFrom(shiny,removeModal) +importFrom(shiny,removeUI) +importFrom(shiny,renderPlot) +importFrom(shiny,renderPrint) +importFrom(shiny,renderText) +importFrom(shiny,req) importFrom(shiny,runApp) +importFrom(shiny,selectInput) +importFrom(shiny,showModal) +importFrom(shiny,sliderInput) +importFrom(shiny,span) +importFrom(shiny,tabPanel) +importFrom(shiny,tagList) +importFrom(shiny,tags) +importFrom(shiny,textInput) +importFrom(shiny,updateSelectInput) +importFrom(shiny,updateSliderInput) +importFrom(shiny,updateTabsetPanel) +importFrom(shiny,updateTextInput) +importFrom(shiny,verbatimTextOutput) importFrom(stats,na.omit) importFrom(stats,setNames) importFrom(utils,getParseData) diff --git a/R/run_nmx.r b/R/run_nmx.r index a397735..11d71f5 100644 --- a/R/run_nmx.r +++ b/R/run_nmx.r @@ -76,7 +76,7 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= }else{ # Handle subsetting (data is loaded in global environment by get_proj function) if(!is.null(meta$subs) && meta$subs!="") data_nlm <- subset(get(meta$data),eval(parse(text=(meta$subs)))) else data_nlm <- get(meta$data) - modres <- nlmixr(eval(parse(text=readLines(proj[[mod]]$model))), data_nlm, est=meta$est,control=meta$control,tableControl(cwres=addcwres, npde=addnpde)) + modres <- nlmixr2::nlmixr(eval(parse(text=readLines(proj[[mod]]$model))), data_nlm, est=meta$est,control=meta$control,nlmixr2::tableControl(cwres=addcwres, npde=addnpde)) if("nlmixr2" %in% rownames(installed.packages())){ ressum <- list(OBJF=modres$objective,CONDNR=modres$conditionNumberCor,partbl=modres$parFixedDf,partblf=modres$parFixed,omega=modres$omega,tottime=rowSums(modres$time)) }else{ diff --git a/R/run_shinymixr.r b/R/run_shinymixr.r index ddff5b7..b1390ce 100644 --- a/R/run_shinymixr.r +++ b/R/run_shinymixr.r @@ -4,7 +4,15 @@ #' @param wd character with the working directory #' @param dry_run logical, if TRUE, the function will not launch the app, but will only create the necessary files #' @param ... arguments passed to the shiny runApp function -#' @importFrom shiny runApp +#' @importFrom shiny runApp HTML NS br checkboxGroupInput checkboxInput conditionalPanel +#' div em eventReactive exportTestValues fluidRow hr icon +#' insertUI isTruthy isolate modalDialog moduleServer +#' numericInput observe observeEvent plotOutput radioButtons reactive +#' reactivePoll reactiveVal reactiveValues reactiveValuesToList +#' removeModal removeUI renderPlot renderPrint renderText req +#' selectInput showModal sliderInput span tabPanel tagList +#' tags textInput updateSelectInput updateSliderInput updateTabsetPanel +#' updateTextInput verbatimTextOutput #' @import bs4Dash ggplot2 gridExtra #' @export #' @return runs the shinyMixR interface diff --git a/R/update_inits.r b/R/update_inits.r index 9782bca..5cd2936 100644 --- a/R/update_inits.r +++ b/R/update_inits.r @@ -25,7 +25,7 @@ update_inits <- function(mod,res,out){ # Get parameters from original model - changes necessary for nlmixr2 2.0.9 #eomod <- ini(get(modnm)) eomod <- get(modnm) - eomod2 <- eval(ini(eomod)) + eomod2 <- eval(nlmixr2::ini(eomod)) eomod2 <- attr(eomod2,"lotriEst") opar <- eomod2[eomod2$fix==FALSE,c("name","est")] opar <- setNames(signif(opar$est,4),opar$name) @@ -37,7 +37,7 @@ update_inits <- function(mod,res,out){ # Update the model with the inits (perform intersect to only update parameters that allign) apar <- rpar[intersect(names(rpar),names(opar))] - outt <- eomod %>% ini(apar) + outt <- eomod %>% nlmixr2::ini(apar) outt <- deparse(outt$fun) outt[1] <- paste(tools::file_path_sans_ext(basename(out)),"<-",outt[1]) writeLines(outt,out) From 23dd2fc80096dc16a018c9e046ec460d2e585cae Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 13:28:37 +0200 Subject: [PATCH 27/41] correctly get proj_obj --- R/module_dataexplore.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/module_dataexplore.R b/R/module_dataexplore.R index 7800078..125606e 100644 --- a/R/module_dataexplore.R +++ b/R/module_dataexplore.R @@ -148,7 +148,7 @@ module_dataexplore_server <- function(id, r) { # Adapt model list based on selected project location observeEvent(r$active_tab,{ if(r$active_tab=="expl"){ - updateSelectInput(session, "mdls", choices = names(get("proj_obj",pos = .GlobalEnv))[names(get("proj_obj",pos = .GlobalEnv))!="meta"],selected=input$mdls) + updateSelectInput(session, "mdls", choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=input$mdls) } },ignoreInit=TRUE) From ff86123f4d7828027e1d2de7e16884256942db88 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 13:28:53 +0200 Subject: [PATCH 28/41] remove `attrl` as not used --- R/exploreplot.r | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/exploreplot.r b/R/exploreplot.r index 1889e5e..03192f3 100644 --- a/R/exploreplot.r +++ b/R/exploreplot.r @@ -105,9 +105,9 @@ exploreplot <- function(inputlist){ if(inputlist$facet1!='[empty]' & inputlist$facet2!='[empty]' & inputlist$facet3!='[empty]') fct <- paste0("~",inputlist$facet1,"+",inputlist$facet2,"+",inputlist$facet3) if(is.na(inputlist$ncol)){ncols <- NULL}else{ncols <- inputlist$ncol} if(!is.null(fct)) add <- c(add,fac=paste0("facet_wrap(",fct,",scales='",inputlist$facetsc,"', labeller=label_both, ncol=",ncols,")")) - - xlb <- ifelse(inputlist$xlab!="",inputlist$xlab, ifelse(inputlist$attrl==TRUE && !is.null(attrl) && !is.null(attrl[[inputlist$Xval1]]$label),attrl[[inputlist$Xval1]]$label,inputlist$Xval1)) - ylb <- ifelse(inputlist$ylab!="",inputlist$ylab, ifelse(inputlist$attrl==TRUE && !is.null(attrl) && !is.null(attrl[[inputlist$Yval1]]$label),attrl[[inputlist$Yval1]]$label,inputlist$Yval1)) + + xlb <- ifelse(inputlist$xlab != "", inputlist$xlab, inputlist$Xval1) + ylb <- ifelse(inputlist$ylab != "", inputlist$ylab, inputlist$Yval1) if(ylb=="[empty]") ylb <- "Count" # y label could only be empty in case of histogram, otherwise y variable should be selected #if(inputlist$xlab!='') add <- c(add,xlab=paste0("xlab('",inputlist$xlab,"')")) #if(inputlist$ylab!='') add <- c(add,ylab=paste0("ylab('",inputlist$ylab,"')")) From 20177aa8a3fce789cbff97f03a7b1e953a984082 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 14:03:36 +0200 Subject: [PATCH 29/41] replace dataIn global assignment --- R/exploreplot.r | 14 +++++++------- R/module_dataexplore.R | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/R/exploreplot.r b/R/exploreplot.r index 03192f3..2e36e9f 100644 --- a/R/exploreplot.r +++ b/R/exploreplot.r @@ -28,10 +28,10 @@ exploreplot <- function(inputlist){ # take into account that colour is used to map colour/fill and shape is used to map shape and linetype inputlist$attrl <- FALSE ggstr <- NULL - if(inputlist$subset=="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(dataIn)") - if(inputlist$subset=="" & inputlist$nondups!="") ggstr <- paste0(ggstr,"\n","ggplot(subset(dataIn, !duplicated(",inputlist$nondups,")))") - if(inputlist$subset!="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(subset(dataIn,",inputlist$subset,"))") - if(inputlist$subset!="" & inputlist$nondups!="") ggstr <- paste0(ggstr,"\n","ggplot(subset(dataIn, !duplicated(",inputlist$nondups,") & ",inputlist$subset,"))") + if(inputlist$subset=="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(r$dataIn)") + if(inputlist$subset=="" & inputlist$nondups!="") ggstr <- paste0(ggstr,"\n","ggplot(subset(r$dataIn, !duplicated(",inputlist$nondups,")))") + if(inputlist$subset!="" & inputlist$nondups=="") ggstr <- paste0(ggstr,"\n","ggplot(subset(r$dataIn,",inputlist$subset,"))") + if(inputlist$subset!="" & inputlist$nondups!="") ggstr <- paste0(ggstr,"\n","ggplot(subset(r$dataIn, !duplicated(",inputlist$nondups,") & ",inputlist$subset,"))") addlay <- function(ageom,ayval,axval,agroup,acolour,ashape,asize,alabel,astats,afcol,afsize,afalph){ if(astats!='[empty]' & ageom%in%c("boxplot","bar","histogram","smooth","jitter","text")) stop("Stats can only be displayed as 'line' or 'point'") @@ -116,9 +116,9 @@ exploreplot <- function(inputlist){ if(inputlist$ptitle!='') add <- c(add,ggtitle=paste0("ggtitle('",inputlist$ptitle,"')")) # set manual color scale or fill in case one of the layers has colors (AND it is set as factor!!) - cond1 <- inputlist$colour1!='[empty]' & grepl(paste0("factor\\(dataIn.",inputlist$colour1),inputlist$precode) - cond2 <- inputlist$colour2!='[empty]' & grepl(paste0("factor\\(dataIn.",inputlist$colour2),inputlist$precode) - cond3 <- inputlist$colour3!='[empty]' & grepl(paste0("factor\\(dataIn.",inputlist$colour3),inputlist$precode) + cond1 <- inputlist$colour1!='[empty]' & grepl(paste0("factor\\(r$dataIn.",inputlist$colour1),inputlist$precode) + cond2 <- inputlist$colour2!='[empty]' & grepl(paste0("factor\\(r$dataIn.",inputlist$colour2),inputlist$precode) + cond3 <- inputlist$colour3!='[empty]' & grepl(paste0("factor\\(r$dataIn.",inputlist$colour3),inputlist$precode) cond4 <- inputlist$colour1!='[empty]' & inputlist$geoms1%in%c("boxplot","bar","histogram") cond5 <- inputlist$colour2!='[empty]' & inputlist$geoms2%in%c("boxplot","bar","histogram") cond6 <- inputlist$colour3!='[empty]' & inputlist$geoms3%in%c("boxplot","bar","histogram") diff --git a/R/module_dataexplore.R b/R/module_dataexplore.R index 125606e..9dd696c 100644 --- a/R/module_dataexplore.R +++ b/R/module_dataexplore.R @@ -152,19 +152,19 @@ module_dataexplore_server <- function(id, r) { } },ignoreInit=TRUE) - # Select different model (for now assign in global environment) + # Select different model (store in reactive values object) updfunc <- function(){ if(input$use_input){ - assign("dataIn",try(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds"))$origData),envir=.GlobalEnv) + r$dataIn <- try(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds"))$origData) }else{ - assign("dataIn",try(as.data.frame(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds")))),envir=.GlobalEnv) + r$dataIn <- try(as.data.frame(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds")))) } - if(!"try-error"%in%class(dataIn)){ + if(!"try-error" %in% class(r$dataIn)){ set1 <- paste0(c("Xval","Yval","group","colour","shape","size","label","facet"),rep(1:3,each=8)) set1 <- lapply(set1,function(x) { - updateSelectInput(session,x,choices=c("[empty]",names(dataIn)),selected=ifelse(input[[x]]=="","[empty]",input[[x]])) + updateSelectInput(session,x,choices=c("[empty]",names(r$dataIn)),selected=ifelse(input[[x]]=="","[empty]",input[[x]])) }) - updateSelectInput(session,"nondups",choices=c("",names(dataIn)),selected="") + updateSelectInput(session,"nondups",choices=c("",names(r$dataIn)),selected="") } } observeEvent(input$mdls,{updfunc()},ignoreInit=TRUE) @@ -207,9 +207,9 @@ module_dataexplore_server <- function(id, r) { upDT <- eventReactive(input$maketbl,{ if(!is.null(input$mdls)){ if(!is.null(input$precode) && input$precode!="") eval(parse(text=input$precode)) - if(!is.null(input$subset) && input$subset!="") eval(parse(text=paste0("dataIn <- subset(dataIn,",input$subset,")"))) - if(!is.null(input$nondups) && input$nondups!="") eval(parse(text=paste0("dataIn <- subset(dataIn, !duplicated(",input$nondups,"))"))) - dataIn + if(!is.null(input$subset) && input$subset!="") eval(parse(text=paste0("r$dataIn <- subset(r$dataIn,",input$subset,")"))) + if(!is.null(input$nondups) && input$nondups!="") eval(parse(text=paste0("r$dataIn <- subset(r$dataIn, !duplicated(",input$nondups,"))"))) + r$dataIn } }) output$tableout <- DT::renderDT(upDT(),options=list(scrollX=TRUE,pageLength=100,lengthMenu=c(10,100,1000,10000))) # Show entire dataset From 6bfc2c393fc5f9db34ca02d759ff085a6cf5b8c1 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 14:07:01 +0200 Subject: [PATCH 30/41] replace deprecated fun.y with fun --- R/exploreplot.r | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/exploreplot.r b/R/exploreplot.r index 2e36e9f..72b9dc2 100644 --- a/R/exploreplot.r +++ b/R/exploreplot.r @@ -65,11 +65,11 @@ exploreplot <- function(inputlist){ aess <- paste(paste(names(aess),aess,sep="="),collapse=", ") if(astats%in%c("mean","median")){ - lay <- paste0("stat_summary","(aes(",aess,"), fun.y=",astats,", geom='", ageom,"', ",argm,")") + lay <- paste0("stat_summary","(aes(",aess,"), fun=",astats,", geom='", ageom,"', ",argm,")") }else if(astats=="mean (SD)"){ - lay <- paste0("stat_summary","(aes(",aess,"), fun.y=mean, fun.ymin=function(x) mean(x) - sd(x), fun.ymax=function(x) mean(x) + sd(x), geom='errorbar', width = 0.2, ",argm,")") + lay <- paste0("stat_summary","(aes(",aess,"), fun=mean, funmin=function(x) mean(x) - sd(x), funmax=function(x) mean(x) + sd(x), geom='errorbar', width = 0.2, ",argm,")") }else if(astats=="median (5-95th perc.)"){ - lay <- paste0("stat_summary","(aes(",aess,"), fun.y=median, fun.ymin=function(x) quantile(x,0.05), fun.ymax=function(x) quantile(x,0.95), geom='errorbar', width = 0.2, ",argm,")") + lay <- paste0("stat_summary","(aes(",aess,"), fun=median, funmin=function(x) quantile(x,0.05), funmax=function(x) quantile(x,0.95), geom='errorbar', width = 0.2, ",argm,")") }else{ lay <- paste0("geom_",ageom,"(aes(",aess,"), ",argm,")") } From 9cd89ff53b69fe76aa0a3935918df99a5c9e5500 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 14:07:11 +0200 Subject: [PATCH 31/41] remove print statements --- R/get_proj.r | 2 -- tests/testthat/test-gof_plot.R | 2 -- 2 files changed, 4 deletions(-) diff --git a/R/get_proj.r b/R/get_proj.r index 943b6f8..7a6145c 100644 --- a/R/get_proj.r +++ b/R/get_proj.r @@ -15,8 +15,6 @@ #' } get_proj <- function(projloc=".",geteval=TRUE){ - print(projloc) - # Read in models and place in result objects dir.create(paste0(projloc,"/shinyMixR/app/shinyMixR"),showWarnings = FALSE,recursive = TRUE) mdln <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE)) diff --git a/tests/testthat/test-gof_plot.R b/tests/testthat/test-gof_plot.R index 9e8d0e9..1f67723 100644 --- a/tests/testthat/test-gof_plot.R +++ b/tests/testthat/test-gof_plot.R @@ -1,7 +1,5 @@ test_that("gof_plot works as expected", { - print(.libPaths()) - res_path <- system.file("/other/run1.res.rds", package = "shinyMixR") res <- readRDS(res_path) From 7b4cd30b385febb5bfe769c928f2093166b9e56d Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 14:14:36 +0200 Subject: [PATCH 32/41] remove data assignment to global env --- R/get_proj.r | 7 ------- 1 file changed, 7 deletions(-) diff --git a/R/get_proj.r b/R/get_proj.r index 7a6145c..721628c 100644 --- a/R/get_proj.r +++ b/R/get_proj.r @@ -27,13 +27,6 @@ get_proj <- function(projloc=".",geteval=TRUE){ datf <- list.files(paste0(projloc,"/shinyMixR/app/data")) grepd <- " |^[[:digit:]]|\\!|\\#|\\$|\\%|\\&|\\'|\\(|\\)|\\-|\\;|\\=|\\@|\\[|\\]|\\^\\`\\{\\|\\}" if(any(grepl(grepd,datf))) warning("Data files with special characters found, take into acount that models that use these can crash") - # not relevant to read all data for running nlmixr in separate session (should be loaded in this session!) - lapply(list.files(paste0(projloc,"/shinyMixR/app/data"),full.names = TRUE),function(x){ - if(!grepl(grepd,x) & !exists(sub("\\.rds$|\\.csv$","",basename(x),ignore.case = TRUE),envir=.GlobalEnv)){ - if(grepl("\\.rds$",x,ignore.case = TRUE)) assign(sub("\\.rds$","",basename(x),ignore.case = TRUE),readRDS(x),pos = .GlobalEnv) - if(grepl("\\.csv$",x,ignore.case = TRUE)) assign(sub("\\.csv$","",basename(x),ignore.case = TRUE),read.csv(x),pos = .GlobalEnv) - } - }) # Read in models and results if(!file.exists(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds"))){ From 6b73e3103ca81ca36560c91a2ca36c08f4aa1f2d Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 14:15:47 +0200 Subject: [PATCH 33/41] add CRAN comments --- .Rbuildignore | 1 + cran-comments.md | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 cran-comments.md diff --git a/.Rbuildignore b/.Rbuildignore index e79996c..14b0478 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ ^_pkgdown\.yml$ ^pkgdown$ ^docs$ +^cran-comments\.md$ diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 0000000..858617d --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,5 @@ +## R CMD check results + +0 errors | 0 warnings | 1 note + +* This is a new release. From e1d63fb2d06fff4b76280640b18bbe6f1b31db07 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 15:25:59 +0200 Subject: [PATCH 34/41] properly rename Dashboard to lowercase --- inst/{Dashboard => dashboard}/app.R | 0 inst/{Dashboard => dashboard}/www/logoshinyMixR.png | Bin 2 files changed, 0 insertions(+), 0 deletions(-) rename inst/{Dashboard => dashboard}/app.R (100%) rename inst/{Dashboard => dashboard}/www/logoshinyMixR.png (100%) diff --git a/inst/Dashboard/app.R b/inst/dashboard/app.R similarity index 100% rename from inst/Dashboard/app.R rename to inst/dashboard/app.R diff --git a/inst/Dashboard/www/logoshinyMixR.png b/inst/dashboard/www/logoshinyMixR.png similarity index 100% rename from inst/Dashboard/www/logoshinyMixR.png rename to inst/dashboard/www/logoshinyMixR.png From 9be5cc5974b8cc3fb9c16118c9cbdf6b5fb713d9 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 15:27:14 +0200 Subject: [PATCH 35/41] properly rename Other to lowercase --- inst/{Other => other}/combined.results.html.r | 0 inst/{Other => other}/eta.plot.arg.r | 0 inst/{Other => other}/eta.plot.r | 0 inst/{Other => other}/pk.1cmt.closed.r | 0 inst/{Other => other}/pk.1cmt.des.r | 0 inst/{Other => other}/run1.r | 0 inst/{Other => other}/run1.res.rds | Bin inst/{Other => other}/run1.ressum.rds | Bin inst/{Other => other}/run_nmx.tmp | 0 inst/{Other => other}/theo_sd.rds | Bin inst/{Other => other}/vpc.plot.r | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename inst/{Other => other}/combined.results.html.r (100%) rename inst/{Other => other}/eta.plot.arg.r (100%) rename inst/{Other => other}/eta.plot.r (100%) rename inst/{Other => other}/pk.1cmt.closed.r (100%) rename inst/{Other => other}/pk.1cmt.des.r (100%) rename inst/{Other => other}/run1.r (100%) rename inst/{Other => other}/run1.res.rds (100%) rename inst/{Other => other}/run1.ressum.rds (100%) rename inst/{Other => other}/run_nmx.tmp (100%) rename inst/{Other => other}/theo_sd.rds (100%) rename inst/{Other => other}/vpc.plot.r (100%) diff --git a/inst/Other/combined.results.html.r b/inst/other/combined.results.html.r similarity index 100% rename from inst/Other/combined.results.html.r rename to inst/other/combined.results.html.r diff --git a/inst/Other/eta.plot.arg.r b/inst/other/eta.plot.arg.r similarity index 100% rename from inst/Other/eta.plot.arg.r rename to inst/other/eta.plot.arg.r diff --git a/inst/Other/eta.plot.r b/inst/other/eta.plot.r similarity index 100% rename from inst/Other/eta.plot.r rename to inst/other/eta.plot.r diff --git a/inst/Other/pk.1cmt.closed.r b/inst/other/pk.1cmt.closed.r similarity index 100% rename from inst/Other/pk.1cmt.closed.r rename to inst/other/pk.1cmt.closed.r diff --git a/inst/Other/pk.1cmt.des.r b/inst/other/pk.1cmt.des.r similarity index 100% rename from inst/Other/pk.1cmt.des.r rename to inst/other/pk.1cmt.des.r diff --git a/inst/Other/run1.r b/inst/other/run1.r similarity index 100% rename from inst/Other/run1.r rename to inst/other/run1.r diff --git a/inst/Other/run1.res.rds b/inst/other/run1.res.rds similarity index 100% rename from inst/Other/run1.res.rds rename to inst/other/run1.res.rds diff --git a/inst/Other/run1.ressum.rds b/inst/other/run1.ressum.rds similarity index 100% rename from inst/Other/run1.ressum.rds rename to inst/other/run1.ressum.rds diff --git a/inst/Other/run_nmx.tmp b/inst/other/run_nmx.tmp similarity index 100% rename from inst/Other/run_nmx.tmp rename to inst/other/run_nmx.tmp diff --git a/inst/Other/theo_sd.rds b/inst/other/theo_sd.rds similarity index 100% rename from inst/Other/theo_sd.rds rename to inst/other/theo_sd.rds diff --git a/inst/Other/vpc.plot.r b/inst/other/vpc.plot.r similarity index 100% rename from inst/Other/vpc.plot.r rename to inst/other/vpc.plot.r From 321b583b410fe7f54f848e6fd75b805652f8a0af Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 15:49:48 +0200 Subject: [PATCH 36/41] increase timeout --- tests/testthat/test-shinymixr-01-model-run1.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-shinymixr-01-model-run1.R b/tests/testthat/test-shinymixr-01-model-run1.R index 9798746..721770a 100644 --- a/tests/testthat/test-shinymixr-01-model-run1.R +++ b/tests/testthat/test-shinymixr-01-model-run1.R @@ -25,7 +25,7 @@ test_that("Shiny app runs model and returns parameters for run1", { # Wait for model to finish (NULL or 0 is the initial value, so we ignore it) app$wait_for_value(export = "modrun-model_updated", ignore = list(NULL, 0), - timeout = 120000) + timeout = 240000) # Test if run is done and 'correct' results have been created Sys.sleep(1) From 7b49c568ac3bc44bacf0caa72820cc560ac2ed9d Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 30 Apr 2024 15:58:44 +0200 Subject: [PATCH 37/41] skip test on CI --- tests/testthat/test-shinymixr-01-model-run1.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-shinymixr-01-model-run1.R b/tests/testthat/test-shinymixr-01-model-run1.R index 721770a..390c7cb 100644 --- a/tests/testthat/test-shinymixr-01-model-run1.R +++ b/tests/testthat/test-shinymixr-01-model-run1.R @@ -5,6 +5,9 @@ test_that("Shiny app runs model and returns parameters for run1", { # Don't run these tests on the CRAN build servers skip_on_cran() + # Don't run this test on CI + skip_on_ci() + # Set up necessary files (internal function) shinyMixR:::setup_shinymixr_test(dir = paste0(tempdir(),"/files"), overwrite = TRUE, @@ -25,7 +28,7 @@ test_that("Shiny app runs model and returns parameters for run1", { # Wait for model to finish (NULL or 0 is the initial value, so we ignore it) app$wait_for_value(export = "modrun-model_updated", ignore = list(NULL, 0), - timeout = 240000) + timeout = 120000) # Test if run is done and 'correct' results have been created Sys.sleep(1) From f9a2d7138b2b1667e06106f5da0bb7617b8f68bc Mon Sep 17 00:00:00 2001 From: RichardHooijmaijers Date: Mon, 6 May 2024 11:11:09 +0200 Subject: [PATCH 38/41] get folder structure right and better way to run app --- DESCRIPTION | 7 ++- R/create_proj.r | 4 +- R/get_proj.r | 21 ++++++--- R/run_shinymixr.r | 113 +++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 123 insertions(+), 22 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ef6dd8c..6a618fe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,7 +4,8 @@ Version: 0.5.0 Authors@R: c(person("Richard", "Hooijmaijers", email = "richardhooijmaijers@gmail.com", role = c("aut", "cre","cph")), person("Teun", "Post", email = "teunpost@gmail.com",role = c("aut","cph")), person("LAPP Consultants",email = "info@lapp.nl", role=c("fnd","cph")), - person("Matthew Fidler",role=c("ctb"))) + person("Matthew Fidler",role=c("ctb")), + person("Veerle van Leemput",role=c("ctb"))) Author: Richard Hooijmaijers Maintainer: Richard Hooijmaijers Description: An interface for the 'nlmixr2' package. Furthermore additional functions @@ -27,7 +28,9 @@ Imports: plotly, cowplot, shinyjs, - ps + ps, + xfun, + fresh Suggests: xpose, xpose.nlmixr2, diff --git a/R/create_proj.r b/R/create_proj.r index ecdede9..72acf68 100644 --- a/R/create_proj.r +++ b/R/create_proj.r @@ -17,7 +17,9 @@ #' } create_proj <- function(loc=".", overwrite=FALSE){ - loc <- paste0(loc, "/shinyMixR/app") + # we want to create subfolders directly in loc, check run_app functionality to see changes there + # for this PR we can save the app in loc/shinyMixR/app, in the end we will not need this + # loc <- paste0(loc, "/shinyMixR/app") if(!dir.exists(loc)) dir.create(loc, recursive = TRUE) diff --git a/R/get_proj.r b/R/get_proj.r index 721628c..64d6a3e 100644 --- a/R/get_proj.r +++ b/R/get_proj.r @@ -16,20 +16,25 @@ get_proj <- function(projloc=".",geteval=TRUE){ # Read in models and place in result objects - dir.create(paste0(projloc,"/shinyMixR/app/shinyMixR"),showWarnings = FALSE,recursive = TRUE) - mdln <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE)) + # dir.create(paste0(projloc,"/shinyMixR/app/shinyMixR"),showWarnings = FALSE,recursive = TRUE) + # mdln <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE)) + dir.create(paste0(projloc,"/shinyMixR"),showWarnings = FALSE,recursive = TRUE) + mdln <- normalizePath(list.files(paste0(projloc,"/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE)) mdlnb <- sub("\\.[r|R]","",basename(mdln)) - sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE)) + #sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE)) + sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE)) sumresi <- file.info(sumres) summdli <- file.info(mdln) # read in data folder (only in case objects are not yet present) - datf <- list.files(paste0(projloc,"/shinyMixR/app/data")) + #datf <- list.files(paste0(projloc,"/shinyMixR/app/data")) + datf <- list.files(paste0(projloc,"/data")) grepd <- " |^[[:digit:]]|\\!|\\#|\\$|\\%|\\&|\\'|\\(|\\)|\\-|\\;|\\=|\\@|\\[|\\]|\\^\\`\\{\\|\\}" if(any(grepl(grepd,datf))) warning("Data files with special characters found, take into acount that models that use these can crash") # Read in models and results - if(!file.exists(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds"))){ + #if(!file.exists(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds"))){ + if(!file.exists(paste0(projloc,"/shinyMixR/project.rds"))){ mdls <- lapply(mdln,list) names(mdls) <- sub("\\.[r|R]","",basename(mdln)) if(length(mdln)==0){ @@ -45,7 +50,8 @@ get_proj <- function(projloc=".",geteval=TRUE){ for(i in sumres) mdls[[sub("\\.ressum\\.rds","",basename(i))]]$results <- readRDS(i) mdls$meta <- list(lastrefresh=Sys.time()) }else{ - mdls <- readRDS(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds")) + #mdls <- readRDS(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds")) + mdls <- readRDS(paste0(projloc,"/shinyMixR/project.rds")) # for the list with models, check if new models are available or old models are deleted # and if models are updated after last refresh: # inproj <- unlist(sapply(mdls[names(mdls)[names(mdls)!="meta"]],"[",1)) @@ -85,6 +91,7 @@ get_proj <- function(projloc=".",geteval=TRUE){ chk <- chk[which(chk$mdlsv>chk$ressv),] #if(nrow(chk)>0) noret <- apply(chk,1,function(x) cat("Be aware that model is saved after results for",x['mdl'],"\n")) - saveRDS(mdls,file=paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds")) + #saveRDS(mdls,file=paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds")) + saveRDS(mdls,file=paste0(projloc,"/shinyMixR/project.rds")) return(mdls) } diff --git a/R/run_shinymixr.r b/R/run_shinymixr.r index b1390ce..a3dffe8 100644 --- a/R/run_shinymixr.r +++ b/R/run_shinymixr.r @@ -22,24 +22,113 @@ #' \dontrun{ #' run_shinymixr(".") #' } -run_shinymixr <- function(wd = getwd(), dry_run = FALSE, ...){ +run_shinymixr <- function(...){ # wd = getwd(), dry_run = FALSE, - if(!file.exists(paste0(wd,"/shinyMixR/app/www"))) try(dir.create(paste0(wd,"/shinyMixR/app/www"),recursive = TRUE)) - if(!file.exists(paste0(wd,"/shinyMixR/app/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/app/shinyMixR/temp"),recursive=TRUE)) + #if(!file.exists(paste0(wd,"/shinyMixR/app/www"))) try(dir.create(paste0(wd,"/shinyMixR/app/www"),recursive = TRUE)) + #if(!file.exists(paste0(wd,"/shinyMixR/app/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/app/shinyMixR/temp"),recursive=TRUE)) + #if(!file.exists(paste0(wd,"/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/temp"),recursive=TRUE)) - try(file.copy(system.file("dashboard","app.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/app.R"),overwrite = TRUE),silent = TRUE) - try(file.copy(system.file("dashboard","www/logoshinyMixR.png",package="shinyMixR"), paste0(wd,"/shinyMixR/app/www/logoshinyMixR.png")),silent = TRUE) + #try(file.copy(system.file("dashboard","app.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/app.R"),overwrite = TRUE),silent = TRUE) + #try(file.copy(system.file("dashboard","www/logoshinyMixR.png",package="shinyMixR"), paste0(wd,"/shinyMixR/app/www/logoshinyMixR.png")),silent = TRUE) # Set the working directory so the project can be found - adpt <- readLines(system.file("dashboard", "app.R", package = "shinyMixR")) - adpt <- c(paste0("setwd(\"", normalizePath(wd, winslash = "/"), "\")"), adpt) - writeLines(adpt, paste0(wd,"/shinyMixR/app/app.R")) + #adpt <- readLines(system.file("dashboard", "app.R", package = "shinyMixR")) + #adpt <- c(paste0("setwd(\"", normalizePath(wd, winslash = "/"), "\")"), adpt) + #writeLines(adpt, paste0(wd,"/shinyMixR/app/app.R")) # Clean up stuff before running the app (check if feasible or not) - try(unlink(list.files(paste0(wd,"/shinyMixR/temp"),pattern=".*prog\\.txt$",full.names = TRUE))) - if (dry_run == TRUE) { - return() + #try(unlink(list.files(paste0(wd,"/shinyMixR/temp"),pattern=".*prog\\.txt$",full.names = TRUE))) + # if (dry_run == TRUE) { + # return() + # } else { + # shiny::runApp(paste0(wd,"/shinyMixR/app"),...) + # } + + if(!file.exists("shinyMixR/temp")) try(dir.create("shinyMixR/temp",recursive=TRUE)) + proj_obj <- get_proj() + # Check and load nlmixr(2) + if ("nlmixr2" %in% rownames(installed.packages())){ + library(nlmixr2) } else { - shiny::runApp(paste0(wd,"/shinyMixR/app"),...) + cat("you need the 'nlmixr2' package to run models\n") } + + newtheme <- fresh::create_theme( + theme = "darkly", # theme has no effect, at least within bs4Dash + fresh::bs4dash_font(size_base = "0.9rem"), + fresh::bs4dash_status(primary = "#3c8dbc") + ) + + shinyApp( + ui = dashboardPage( + title = "shinyMixR", + # Header + header = dashboardHeader( + title = dashboardBrand(title = "ShinyMixR", color = "lightblue"), #, color = "lightblue", href = "#", image = "logoshinyMixR.png"), + leftUI = tags$img(src=paste0("data:image/png;base64,",xfun::base64_encode(system.file("dashboard/www/logoshinyMixR.png", package = "shinyMixR"))),height=40) + ), + # Sidebar menu + sidebar = dashboardSidebar(status="lightblue", elevation = 1, + sidebarMenu(id="tabs", + menuItem('Model overview', tabName='overview', icon=icon('table')), + menuItem('Edit model(s)', tabName='editor', icon=icon('file-pen')), + menuItem('Run model(s)', tabName='run', icon=icon('person-running')), + menuItem('Parameter estimates', tabName='par', icon=icon('table-cells')), + menuItem('Goodness of fit', tabName='gof', icon=icon('chart-line')), + menuItem('Fit plots', tabName='fitpl', icon=icon('chart-line')), + menuItem('Data exploration', tabName='expl', icon=icon('magnifying-glass')), + menuItem('Settings', tabName='settings', icon=icon('gear')) + ) + ), + # Main body + body = dashboardBody( + # First set theme and include css + fresh::use_theme(newtheme), + # CHECK IF THE LINES BELOW WILL WORK WITHOUT INTERNET CONNECTION AND DOES IT FAIL GRACEFULLY?! + shinyWidgets::useSweetAlert("minimal"), + tags$style("@import url(https://use.fontawesome.com/releases/v6.3.0/css/all.css);"), + tags$head(tags$style(HTML(".shiny-split-layout > div {overflow: visible;}"))), + tags$head(tags$style("#progph{overflow-y:scroll; max-height: 600px;}")), + tags$head(tags$style(HTML("#exploretabout{height: 75vh; overflow-y: auto;}"))), + tags$head(tags$style(HTML(".swal2-popup {font-size: 0.9rem !important;}"))), + tags$head(tags$style(HTML("input[id$=\"subset\"]{font-family:\"Courier New\"}"))), + tags$head(tags$style(HTML("input[id$=\"precode\"]{font-family:\"Courier New\"}"))), + tags$head(tags$style(HTML("label{margin-bottom:0rem;}"))), + tabItems( + tabItem(tabName = "overview", module_overview_ui("oview")), + tabItem(tabName = "editor", module_edit_ui("editor")), + tabItem(tabName = "run", module_run_ui("modrun", proj_obj)), + tabItem(tabName = "par", module_pt_ui("partable", proj_obj)), + tabItem(tabName = "gof", module_gof_ui("gofplots", proj_obj)), + tabItem(tabName = "fitpl", module_fitplots_ui("fitplots", proj_obj)), + tabItem(tabName = "expl", module_dataexplore_ui("explore")), + tabItem(tabName = "settings", module_settings_ui("settings")) + ) + ) + ), + server = function(input, output, session) { + # Top-level reactive values + r <- reactiveValues(active_tab = "", + model_updated = 0, + proj_obj = get_proj(), + this_wd = ".") + + observeEvent(input$tabs, r$active_tab <- input$tabs) + + # Modules + sett <- module_settings_server("settings") + module_overview_server("oview", r = r) + module_edit_server("editor", r = r, settings=sett) + module_run_server("modrun", r = r) + module_pt_server("partable", r = r) + module_gof_server("gofplots", r = r,settings=sett) + module_fitplots_server("fitplots", r = r,settings=sett) + module_dataexplore_server("explore", r = r) + + }, + options = list(launch.browser=TRUE,...) # set general options here for running the app + ) + + + } From 707acf1bd7d16d9d8b89bdd5ab18d28ab7245097 Mon Sep 17 00:00:00 2001 From: RichardHooijmaijers Date: Mon, 6 May 2024 16:15:17 +0200 Subject: [PATCH 39/41] changes for folder structure mainly for wd --- DESCRIPTION | 4 +-- NAMESPACE | 2 ++ R/module_dataexplore.R | 4 +-- R/module_edit.R | 17 ++++++---- R/module_fitplots.R | 4 +-- R/module_gof.R | 4 +-- R/module_metadata.R | 6 ++-- R/module_overview.R | 12 +++---- R/module_run.R | 14 ++++---- R/run_nmx.r | 4 +-- R/run_shinymixr.r | 33 ++++++++++--------- R/utils.R | 12 +++---- inst/other/run_nmx.tmp | 2 +- man/run_shinymixr.Rd | 4 +-- man/shinyMixR-package.Rd | 1 + tests/testthat.R | 1 + tests/testthat/test-shinymixr-01-model-run1.R | 7 ++-- .../test-shinymixr-02-parameter-table.R | 3 +- .../test-shinymixr-03-create-newmodel.R | 10 +++--- 19 files changed, 77 insertions(+), 67 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6a618fe..500d016 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,11 +30,11 @@ Imports: shinyjs, ps, xfun, - fresh + fresh, + nlmixr2 Suggests: xpose, xpose.nlmixr2, - nlmixr2, nlme, testthat, shinytest2, diff --git a/NAMESPACE b/NAMESPACE index a522d1f..5cdd973 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -42,6 +42,7 @@ export(update_inits) import(bs4Dash) import(ggplot2) import(gridExtra) +import(nlmixr2) importFrom(magrittr,"%>%") importFrom(shiny,HTML) importFrom(shiny,NS) @@ -79,6 +80,7 @@ importFrom(shiny,renderText) importFrom(shiny,req) importFrom(shiny,runApp) importFrom(shiny,selectInput) +importFrom(shiny,shinyApp) importFrom(shiny,showModal) importFrom(shiny,sliderInput) importFrom(shiny,span) diff --git a/R/module_dataexplore.R b/R/module_dataexplore.R index 9dd696c..ddb4576 100644 --- a/R/module_dataexplore.R +++ b/R/module_dataexplore.R @@ -155,9 +155,9 @@ module_dataexplore_server <- function(id, r) { # Select different model (store in reactive values object) updfunc <- function(){ if(input$use_input){ - r$dataIn <- try(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds"))$origData) + r$dataIn <- try(readRDS(paste0(r$this_wd,"/shinyMixR/",input$mdls[1],".res.rds"))$origData) }else{ - r$dataIn <- try(as.data.frame(readRDS(paste0("shinyMixR/",input$mdls[1],".res.rds")))) + r$dataIn <- try(as.data.frame(readRDS(paste0(r$this_wd,"/shinyMixR/",input$mdls[1],".res.rds")))) } if(!"try-error" %in% class(r$dataIn)){ set1 <- paste0(c("Xval","Yval","group","colour","shape","size","label","facet"),rep(1:3,each=8)) diff --git a/R/module_edit.R b/R/module_edit.R index e16dbd1..318d1d9 100644 --- a/R/module_edit.R +++ b/R/module_edit.R @@ -62,10 +62,10 @@ module_edit_server <- function(id, r, settings) { mdl <- try(readLines(system.file(paste0("other/",input$templnew,".r"),package="shinyMixR"))) if(!"try-error"%in%class(mdl)){ mdl <- sub("run1",sub("\\.[r|R]","",input$namenew),mdl) - writeLines(mdl,paste0("models/",input$namenew)) + writeLines(mdl,paste0(r$this_wd,"/models/",input$namenew)) r$proj_obj <- get_proj(r$this_wd) updateSelectInput(session,"editLst",choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=sub("\\.[r|R]","",input$namenew)) - shinyAce::updateAceEditor(session,"editor",value=paste(readLines(paste0("models/",input$namenew)),collapse="\n")) + shinyAce::updateAceEditor(session,"editor",value=paste(readLines(paste0(r$this_wd,"/models/",input$namenew)),collapse="\n")) removeModal() } }) @@ -103,7 +103,7 @@ module_edit_server <- function(id, r, settings) { selm <- incm <- NULL } modalDialog(title="Update initial estimates",easyClose = TRUE,size="l", - selectInput(ns("finest"),"Final estimates from",sub("\\.res\\.rds","",list.files("shinyMixR",pattern="res.rds")), selected = selm, multiple=FALSE), + selectInput(ns("finest"),"Final estimates from",sub("\\.res\\.rds","",list.files(paste0(r$this_wd,"/shinyMixR"),pattern="res.rds")), selected = selm, multiple=FALSE), textInput(ns("tosave"),"Save as",incm), actionButton(ns("goupdate"), "Go",icon=icon("play")) ) @@ -112,11 +112,14 @@ module_edit_server <- function(id, r, settings) { observeEvent(input$goupdate,{ if(isTruthy(input$finest) && isTruthy(input$tosave)){ #res <- try(update_inits(input$editor,paste0("shinyMixr/",input$finest,".res.rds"),paste0("models/",input$tosave))) - res <- try(update_inits(readLines(paste0("models/",input$finest,".r")), - paste0("shinyMixr/",input$finest,".res.rds"), - paste0("models/",input$tosave))) + #cat("getting stuff from",paste0(r$this_wd,"/models/",input$finest,".r"),"with results from",paste0(r$this_wd,"/shinyMixr/",input$finest,".res.rds"), + # "to model",paste0(r$this_wd,"/models/",input$tosave)) + res <- try(update_inits(readLines(paste0(r$this_wd,"/models/",input$finest,".r")), + paste0(r$this_wd,"/shinyMixr/",input$finest,".res.rds"), + paste0(r$this_wd,"/models/",input$tosave))) if("try-error"%in%class(res)){ - myalert("Could not update initials",type = "error") + #myalert("Could not update initials",type = "error") + myalert(res,type = "error") }else{ r$proj_obj <- get_proj(r$this_wd) updateSelectInput(session,"editLst",choices = names(r$proj_obj)[names(r$proj_obj)!="meta"],selected=sub("\\.[r|R]","",input$tosave)) diff --git a/R/module_fitplots.R b/R/module_fitplots.R index 96dec25..6c44eb0 100644 --- a/R/module_fitplots.R +++ b/R/module_fitplots.R @@ -53,7 +53,7 @@ module_fitplots_server <- function(id, r, settings) { # Adapt the selection of variables when model is selected observeEvent(input$fitLst,{ - datar <- try(readRDS(paste0("shinyMixR/",input$fitLst,".res.rds"))) + datar <- try(readRDS(paste0(r$this_wd,"/shinyMixR/",input$fitLst,".res.rds"))) if(!"try-error"%in%class(datar)){ updateSelectInput(session, "by", choices = c("",names(datar)),selected="ID") updateSelectInput(session, "idv", choices = c("",names(datar)),selected="TIME") @@ -69,7 +69,7 @@ module_fitplots_server <- function(id, r, settings) { # Create fit plot (type of plot taken from settings!) fitpl <- function(inp,saveit=FALSE){ #cat("got clicked\n") - dataIn <- readRDS(paste0("shinyMixR/",input$fitLst[1],".res.rds")) + dataIn <- readRDS(paste0(r$this_wd,"/shinyMixR/",input$fitLst[1],".res.rds")) if(inp$subset!="") dataIn <- subset(dataIn,eval(parse(text=input$subset))) if(inp$precode!="") eval(parse(text=input$precode)) if(!isTruthy(inp$by)) byr <- NULL else byr <- inp$by diff --git a/R/module_gof.R b/R/module_gof.R index e625c58..1a76989 100644 --- a/R/module_gof.R +++ b/R/module_gof.R @@ -49,7 +49,7 @@ module_gof_server <- function(id, r, settings) { # Adapt the selection of variables when model is selected observeEvent(input$gofLst,{ - datar <- try(readRDS(paste0("shinyMixR/",input$gofLst,".res.rds"))) + datar <- try(readRDS(paste0(r$this_wd,"/shinyMixR/",input$gofLst,".res.rds"))) if(!"try-error"%in%class(datar)){ updateSelectInput(session, "colby", choices = c("",names(datar))) }else{ @@ -59,7 +59,7 @@ module_gof_server <- function(id, r, settings) { # Create GOF plot (type of plot taken from settings!) gofpl <- function(inp,saveit=FALSE){ - dataIn <- readRDS(paste0("shinyMixR/",inp$gofLst,".res.rds")) + dataIn <- readRDS(paste0(r$this_wd,"/shinyMixR/",inp$gofLst,".res.rds")) if(inp$subset!="") dataIn <- subset(dataIn,eval(parse(text=input$subset))) if(inp$precode!="") eval(parse(text=input$precode)) if(inp$colby=="") clr <- NULL else clr <- inp$colby diff --git a/R/module_metadata.R b/R/module_metadata.R index 1f6463f..a1584c9 100644 --- a/R/module_metadata.R +++ b/R/module_metadata.R @@ -53,7 +53,7 @@ module_metadata_server <- function(id,type,selline=NULL,sellmod=NULL,sellcont=NU gen <- tagList( sliderInput(ns("mdlimp"), "Importance", 0, 4, meta$imp, step = 1, round = TRUE), textInput(ns("mdldesc"),"Description",value=meta$desc), - selectInput(ns("mdlref"),"Reference",meta$ref,choices=tools::file_path_sans_ext(list.files("models")),multiple=FALSE,selectize = TRUE), + selectInput(ns("mdlref"),"Reference",meta$ref,choices=tools::file_path_sans_ext(list.files(paste0(r$this_wd,"/models"))),multiple=FALSE,selectize = TRUE), textInput(ns("mdldata"),"Data",value=meta$data), selectInput(ns("mdlest"),"Method",c("fo", "foce", "focei", "foi", "nlme", "posthoc", "predict", "rxSolve", "saem", "simulate"),selected=meta$est), actionButton(ns("adpt"), "Save",icon=icon("floppy-disk")) @@ -99,9 +99,9 @@ module_metadata_server <- function(id,type,selline=NULL,sellmod=NULL,sellcont=NU tmpmod <- tempfile() writeLines(sellcont(),tmpmod) #toret <- c(name=paste0("models/",sellmod(),".r"), val=input$mdladpt, saveas=paste0("models/",input$mdladpt)) - toret <- c(name=tmpmod, val=input$mdladpt, saveas=paste0("models/",input$mdladpt)) + toret <- c(name=tmpmod, val=input$mdladpt, saveas=paste0(r$this_wd,"/models/",input$mdladpt)) }else{ - toret <- c(name=paste0("models/",input$mdladpt,".r"), val="Update DT", saveas=paste0("models/",input$mdladpt,".r")) + toret <- c(name=paste0(r$this_wd,"/models/",input$mdladpt,".r"), val="Update DT", saveas=paste0(r$this_wd,"/models/",input$mdladpt,".r")) } towr <- adpt_meta(toret['name'],metanfo) if(type=="save") towr <- sub(sellmod(),sub("\\.[r|R]","",input$mdladpt),towr) diff --git a/R/module_overview.R b/R/module_overview.R index 9b2e710..9a8a816 100644 --- a/R/module_overview.R +++ b/R/module_overview.R @@ -90,7 +90,7 @@ module_overview_server <- function(id, r) { hr_out <- eventReactive(input$hlr, { sel <- sort(names(r$proj_obj)[names(r$proj_obj)!="meta"])[input$overview_tbl_rows_selected] if(length(sel)>0){ - res <- try(readRDS(paste0("shinyMixR/",sel[1],".res.rds"))) + res <- try(readRDS(paste0(r$this_wd,"/shinyMixR/",sel[1],".res.rds"))) if(!"try-error"%in%class(res)) print(res) else print("No results available") } }) @@ -109,18 +109,18 @@ module_overview_server <- function(id, r) { if(!is.null(input$overview_tbl_rows_selected)){ msel <- sort(names(r$proj_obj)[names(r$proj_obj)!="meta"])[input$overview_tbl_rows_selected] if(input$delmodall) { - try(file.remove(paste0("shinyMixR/",msel,".res.rds"))) - try(file.remove(paste0("shinyMixR/",msel,".ressum.rds"))) - try(unlink(paste0("analysis/",msel),recursive = TRUE)) + try(file.remove(paste0(r$this_wd,"/shinyMixR/",msel,".res.rds"))) + try(file.remove(paste0(r$this_wd,"/shinyMixR/",msel,".ressum.rds"))) + try(unlink(paste0(r$this_wd,"/analysis/",msel),recursive = TRUE)) } - try(file.remove(paste0("models/",msel,".r"))) + try(file.remove(paste0(r$this_wd,"/models/",msel,".r"))) r$proj_obj <- get_proj(r$this_wd) DT::replaceData(proxy, overview(r$proj_obj), rownames = FALSE) removeModal() } },ignoreInit = TRUE) - module_scripts_server("runscripts", files = reactive(r$mdls), scripts = reactive(r$scrpt), loc = "shinyMixR/temp") + module_scripts_server("runscripts", files = reactive(r$mdls), scripts = reactive(r$scrpt), loc = paste0(r$this_wd,"/shinyMixR/temp")) # Creating reports module_reports_server("reports") diff --git a/R/module_run.R b/R/module_run.R index aecb8dd..7b87057 100644 --- a/R/module_run.R +++ b/R/module_run.R @@ -37,10 +37,10 @@ module_run_server <- function(id, r) { # Run model observeEvent(input$runMdl,{ - unlink(list.files(paste0("shinyMixR/temp"),pattern=".*prog\\.txt$",full.names = TRUE)) + unlink(list.files(paste0(r$this_wd,"/shinyMixR/temp"),pattern=".*prog\\.txt$",full.names = TRUE)) # Perform tests before running - if(!is.null(input$runLst)){ - proj <- r$proj_obj + if(!is.null(input$runLst)){ + proj <- r$proj_obj checkall <- unlist(sapply(input$runLst,function(x){ chk <- proj[[x]]$model chksrc <- try(source(chk,local=TRUE),silent=TRUE) @@ -51,12 +51,12 @@ module_run_server <- function(id, r) { } })) if(length(checkall)>0){ - myalert(paste("The following issues occured:",paste0(names(checkall),": ",checkall,collapse=", ")),type = "error") + myalert(paste("The following issues occured:",paste0(names(checkall),": ",checkall,collapse=", ")),type = "error") }else{ myalert("model(s) submitted, wait for progress log to pop-up!",type = "succes") addcwres <- ifelse("Add CWRES to output"%in%input$addExtra,TRUE,FALSE) addnpde <- ifelse("Add NPDE to output"%in%input$addExtra,TRUE,FALSE) - lapply(input$runLst,function(mods) run_nmx(mods, r$proj_obj, addcwres=addcwres,addnpde=addnpde)) + lapply(input$runLst,function(mods) run_nmx(mods, r$proj_obj, addcwres=addcwres,addnpde=addnpde,projloc=r$this_wd)) } }else{ myalert("Please select models to run",type = "error") @@ -65,14 +65,14 @@ module_run_server <- function(id, r) { # Get progress log runmodmonit <- reactivePoll(500, session, checkFunc = function() { - progf <- list.files("shinyMixR/temp",pattern="prog\\.txt$",full.names = TRUE) + progf <- list.files(paste0(r$this_wd,"/shinyMixR/temp"),pattern="prog\\.txt$",full.names = TRUE) if (length(progf)>0) max(file.info(progf)$mtime) else "" }, valueFunc = function() { - progFn <- list.files("shinyMixR/temp",pattern="prog\\.txt$",full.names = TRUE) + progFn <- list.files(paste0(r$this_wd,"/shinyMixR/temp"),pattern="prog\\.txt$",full.names = TRUE) paste(unlist(lapply(progFn,function(x) c(paste0("\n ***************",x,"***************"),readLines(x, warn = FALSE)))),collapse="\n") } ) diff --git a/R/run_nmx.r b/R/run_nmx.r index 11d71f5..e1b646a 100644 --- a/R/run_nmx.r +++ b/R/run_nmx.r @@ -32,7 +32,7 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= # if(autoupdate) assign(dnm,get_proj(projloc=projloc)) # Source model to obtain meta data (places meta object in env) sret <- try(source(proj[[mod]]$model,local=TRUE)) - meta <- try(eval(parse(text=c("nlmixr(",readLines(proj[[mod]]$model),")$meta")))) + meta <- try(eval(parse(text=c("nlmixr2::nlmixr(",readLines(proj[[mod]]$model),")$meta")))) if(inherits(meta, "try-error") || inherits(sret, "try-error")){ cat("Error in model syntax please check before running\n") if(ext) writeLines(meta, paste0(projloc,"/shinyMixR/temp/",mod,".prog.txt")) @@ -59,7 +59,7 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= control=cntrll, saveres=saverds, modelname=mod, - locproj=projloc, + locproj=normalizePath(projloc,winslash = "/"), addcwres=addcwres, addnpde=addnpde) diff --git a/R/run_shinymixr.r b/R/run_shinymixr.r index a3dffe8..59f4dad 100644 --- a/R/run_shinymixr.r +++ b/R/run_shinymixr.r @@ -2,7 +2,6 @@ #' Creates and run the interface #' #' @param wd character with the working directory -#' @param dry_run logical, if TRUE, the function will not launch the app, but will only create the necessary files #' @param ... arguments passed to the shiny runApp function #' @importFrom shiny runApp HTML NS br checkboxGroupInput checkboxInput conditionalPanel #' div em eventReactive exportTestValues fluidRow hr icon @@ -22,7 +21,7 @@ #' \dontrun{ #' run_shinymixr(".") #' } -run_shinymixr <- function(...){ # wd = getwd(), dry_run = FALSE, +run_shinymixr <- function(wd = getwd(),...){ #if(!file.exists(paste0(wd,"/shinyMixR/app/www"))) try(dir.create(paste0(wd,"/shinyMixR/app/www"),recursive = TRUE)) #if(!file.exists(paste0(wd,"/shinyMixR/app/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/app/shinyMixR/temp"),recursive=TRUE)) @@ -43,15 +42,19 @@ run_shinymixr <- function(...){ # wd = getwd(), dry_run = FALSE, # } else { # shiny::runApp(paste0(wd,"/shinyMixR/app"),...) # } - - if(!file.exists("shinyMixR/temp")) try(dir.create("shinyMixR/temp",recursive=TRUE)) - proj_obj <- get_proj() - # Check and load nlmixr(2) - if ("nlmixr2" %in% rownames(installed.packages())){ - library(nlmixr2) - } else { - cat("you need the 'nlmixr2' package to run models\n") - } + #owd <- getwd() + #if(normalizePath(owd)!=normalizePath(wd)) setwd(wd) + #cat("I am in ",getwd(),"\n") + #on.exit(setwd(owd)) + #if(!file.exists("shinyMixR/temp")) try(dir.create("shinyMixR/temp",recursive=TRUE)) + if(!file.exists(paste0(wd,"/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/temp"),recursive=TRUE)) + proj_obj <- get_proj(wd) + # Check and load nlmixr(2); set nlmixr2 as import so needed when package is loaded and this is also a CRAN warning + # if ("nlmixr2" %in% rownames(installed.packages())){ + # library(nlmixr2) + # } else { + # cat("you need the 'nlmixr2' package to run models\n") + # } newtheme <- fresh::create_theme( theme = "darkly", # theme has no effect, at least within bs4Dash @@ -110,8 +113,8 @@ run_shinymixr <- function(...){ # wd = getwd(), dry_run = FALSE, # Top-level reactive values r <- reactiveValues(active_tab = "", model_updated = 0, - proj_obj = get_proj(), - this_wd = ".") + proj_obj = get_proj(wd), + this_wd = wd) observeEvent(input$tabs, r$active_tab <- input$tabs) @@ -128,7 +131,5 @@ run_shinymixr <- function(...){ # wd = getwd(), dry_run = FALSE, }, options = list(launch.browser=TRUE,...) # set general options here for running the app ) - - - + #cat("I was in ",getwd(),"\n") } diff --git a/R/utils.R b/R/utils.R index db6efa3..86ba81d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -19,18 +19,18 @@ setup_shinymixr_test <- function(dir = "./tests/files", overwrite = TRUE, record } create_proj(dir, overwrite = overwrite) - run_shinymixr(wd = dir, dry_run = TRUE) + #run_shinymixr(wd = dir, dry_run = TRUE) if(incres){ file.copy(system.file(c("other/run1.res.rds","other/run1.ressum.rds"),package="shinyMixR"), - paste0(dir,"/shinyMixR/app/shinyMixR")) + paste0(dir,"/shinyMixR")) } # create .Rprofile file to store settings - if (!file.exists(paste0(dir, "/.Rprofile"))) { - writeLines("options(shiny.testmode = TRUE)", - con = paste0(dir, "/shinyMixR/app/.Rprofile")) - } + # if (!file.exists(paste0(dir, "/.Rprofile"))) { + # writeLines("options(shiny.testmode = TRUE)", + # con = paste0(dir, "/shinyMixR/app/.Rprofile")) + # } if (record == TRUE) { shinytest2::record_test(paste0(dir, "/shinyMixR/app")) diff --git a/inst/other/run_nmx.tmp b/inst/other/run_nmx.tmp index 14f07a6..b60436f 100644 --- a/inst/other/run_nmx.tmp +++ b/inst/other/run_nmx.tmp @@ -21,7 +21,7 @@ if("{{subs}}"!=""){ source("{{{modelloc}}}") setwd("{{{locproj}}}/shinyMixR/temp") -modres <- try(nlmixr({{{modelname}}}, data=data_nlm, est="{{{est}}}",control={{{control}}},table=tableControl(cwres={{{addcwres}}}, npde={{{addnpde}}}))) +modres <- try(nlmixr2::nlmixr({{{modelname}}}, data=data_nlm, est="{{{est}}}",control={{{control}}},table=tableControl(cwres={{{addcwres}}}, npde={{{addnpde}}}))) {{#saveres}} if(length(class(modres))>1 && !"try-error"%in%class(modres)){ diff --git a/man/run_shinymixr.Rd b/man/run_shinymixr.Rd index 2147236..d78aef5 100644 --- a/man/run_shinymixr.Rd +++ b/man/run_shinymixr.Rd @@ -4,13 +4,11 @@ \alias{run_shinymixr} \title{Creates and run the interface} \usage{ -run_shinymixr(wd = getwd(), dry_run = FALSE, ...) +run_shinymixr(wd = getwd(), ...) } \arguments{ \item{wd}{character with the working directory} -\item{dry_run}{logical, if TRUE, the function will not launch the app, but will only create the necessary files} - \item{...}{arguments passed to the shiny runApp function} } \value{ diff --git a/man/shinyMixR-package.Rd b/man/shinyMixR-package.Rd index 3ee053c..c1a2009 100644 --- a/man/shinyMixR-package.Rd +++ b/man/shinyMixR-package.Rd @@ -20,6 +20,7 @@ Other contributors: \itemize{ \item LAPP Consultants \email{info@lapp.nl} [funder, copyright holder] \item Matthew Fidler [contributor] + \item Veerle van Leemput [contributor] } } diff --git a/tests/testthat.R b/tests/testthat.R index bfa1583..4932974 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -3,6 +3,7 @@ options(chromote.timeout = 120) library(testthat) library(shinyMixR) +library(nlmixr2) test_check("shinyMixR") # devtools::test() diff --git a/tests/testthat/test-shinymixr-01-model-run1.R b/tests/testthat/test-shinymixr-01-model-run1.R index 390c7cb..97cfdb6 100644 --- a/tests/testthat/test-shinymixr-01-model-run1.R +++ b/tests/testthat/test-shinymixr-01-model-run1.R @@ -14,7 +14,8 @@ test_that("Shiny app runs model and returns parameters for run1", { record = FALSE) # Start driver for Shiny test - app <- AppDriver$new(app_dir = paste0(tempdir(),"/files/shinyMixR/app/"), + shiny_app <- shinyMixR::run_shinymixr(paste0(tempdir(),"/files")) + app <- AppDriver$new(app_dir = shiny_app, name = "run1-model", seed = 123) @@ -32,10 +33,10 @@ test_that("Shiny app runs model and returns parameters for run1", { # Test if run is done and 'correct' results have been created Sys.sleep(1) - rundone <- "run1.res.rds"%in%list.files(paste0(tempdir(),"/files/shinyMixR/app/shinyMixR")) + rundone <- "run1.res.rds"%in%list.files(paste0(tempdir(),"/files/shinyMixR")) expect_true(rundone) if(rundone){ - runres <- readRDS(paste0(tempdir(),"/files/shinyMixR/app/shinyMixR/run1.res.rds")) + runres <- readRDS(paste0(tempdir(),"/files/shinyMixR/run1.res.rds")) expect_true(inherits(runres,"nlmixr2FitData")) } diff --git a/tests/testthat/test-shinymixr-02-parameter-table.R b/tests/testthat/test-shinymixr-02-parameter-table.R index ff78a0d..6be705f 100644 --- a/tests/testthat/test-shinymixr-02-parameter-table.R +++ b/tests/testthat/test-shinymixr-02-parameter-table.R @@ -11,7 +11,8 @@ test_that("Shiny app creates correct parameter table", { record = FALSE, incres = TRUE) # Start driver for Shiny test - app <- AppDriver$new(app_dir = paste0(tempdir(),"/files/shinyMixR/app/"), + shiny_app <- shinyMixR::run_shinymixr(paste0(tempdir(),"/files")) + app <- AppDriver$new(app_dir = shiny_app, name = "run2-model", seed = 123) diff --git a/tests/testthat/test-shinymixr-03-create-newmodel.R b/tests/testthat/test-shinymixr-03-create-newmodel.R index 708d68e..31b9633 100644 --- a/tests/testthat/test-shinymixr-03-create-newmodel.R +++ b/tests/testthat/test-shinymixr-03-create-newmodel.R @@ -14,7 +14,8 @@ test_that("Shiny app correctly creates new model code", { incres = TRUE) # Start driver for Shiny test - app <- AppDriver$new(app_dir = paste0(temp_dir, "/files/shinyMixR/app/"), + shiny_app <- shinyMixR::run_shinymixr(paste0(tempdir(),"/files")) + app <- AppDriver$new(app_dir = shiny_app, name = "run3-model", seed = 123) @@ -32,10 +33,10 @@ test_that("Shiny app correctly creates new model code", { app$expect_values(input = "editor-newgo") # Check if new model is created and contains correct naming - modmade <- "run2.r" %in% list.files(paste0(temp_dir, "/files/shinyMixR/app/models")) + modmade <- "run2.r" %in% list.files(paste0(temp_dir, "/files/models")) expect_true(modmade) if(modmade){ - modcont <- readLines(paste0(temp_dir, "/files/shinyMixR/app/models/run2.r")) + modcont <- readLines(paste0(temp_dir, "/files/models/run2.r")) expect_true(grepl("run2 <- function", modcont[1])) } @@ -49,9 +50,10 @@ test_that("Shiny app correctly creates new model code", { expect_true(curvals$input$`editor-adapt_meta_ed-mdlimp`==1) app$click("editor-adapt_meta_ed-adpt") app$click(selector = ".swal2-confirm") - expect_true("run3.r"%in%list.files(paste0(tempdir(),"/files/shinyMixR/app/models"))) + expect_true("run3.r"%in%list.files(paste0(tempdir(),"/files/models"))) # Finally test if update inits works as expected (e.g. are initial changed, values itself tested outside shinytest) + app$set_inputs(`editor-editLst` = "run1") app$click("editor-updinit") Sys.sleep(1) app$set_inputs("editor-tosave" = c("run99.r")) From f58b8f0bcd5e2bcd0d4d84a1d1c91ba1bddfafe8 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Tue, 7 May 2024 16:28:25 +0200 Subject: [PATCH 40/41] fix: typo --- R/exploreplot.r | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/exploreplot.r b/R/exploreplot.r index 72b9dc2..1358c38 100644 --- a/R/exploreplot.r +++ b/R/exploreplot.r @@ -67,9 +67,9 @@ exploreplot <- function(inputlist){ if(astats%in%c("mean","median")){ lay <- paste0("stat_summary","(aes(",aess,"), fun=",astats,", geom='", ageom,"', ",argm,")") }else if(astats=="mean (SD)"){ - lay <- paste0("stat_summary","(aes(",aess,"), fun=mean, funmin=function(x) mean(x) - sd(x), funmax=function(x) mean(x) + sd(x), geom='errorbar', width = 0.2, ",argm,")") + lay <- paste0("stat_summary","(aes(",aess,"), fun=mean, fun.min=function(x) mean(x) - sd(x), fun.max=function(x) mean(x) + sd(x), geom='errorbar', width = 0.2, ",argm,")") }else if(astats=="median (5-95th perc.)"){ - lay <- paste0("stat_summary","(aes(",aess,"), fun=median, funmin=function(x) quantile(x,0.05), funmax=function(x) quantile(x,0.95), geom='errorbar', width = 0.2, ",argm,")") + lay <- paste0("stat_summary","(aes(",aess,"), fun=median, fun.min=function(x) quantile(x,0.05), fun.max=function(x) quantile(x,0.95), geom='errorbar', width = 0.2, ",argm,")") }else{ lay <- paste0("geom_",ageom,"(aes(",aess,"), ",argm,")") } From 84528e2e07e730dab51879e49cb306c2f21a8b76 Mon Sep 17 00:00:00 2001 From: RichardHooijmaijers Date: Tue, 14 May 2024 11:31:20 +0200 Subject: [PATCH 41/41] Cleaned code from unnecessary comments --- R/create_proj.r | 4 ---- R/get_proj.r | 12 ------------ R/gof_plot.r | 3 --- R/module_edit.R | 4 ---- R/module_gof.R | 2 -- R/module_overview.R | 2 -- R/module_partable.R | 3 --- R/module_reports.R | 2 -- R/run_nmx.r | 3 --- R/run_shinymixr.r | 31 ------------------------------- R/utils.R | 1 - 11 files changed, 67 deletions(-) diff --git a/R/create_proj.r b/R/create_proj.r index 72acf68..639323e 100644 --- a/R/create_proj.r +++ b/R/create_proj.r @@ -17,10 +17,6 @@ #' } create_proj <- function(loc=".", overwrite=FALSE){ - # we want to create subfolders directly in loc, check run_app functionality to see changes there - # for this PR we can save the app in loc/shinyMixR/app, in the end we will not need this - # loc <- paste0(loc, "/shinyMixR/app") - if(!dir.exists(loc)) dir.create(loc, recursive = TRUE) # First create the folder structure diff --git a/R/get_proj.r b/R/get_proj.r index 64d6a3e..959c6c8 100644 --- a/R/get_proj.r +++ b/R/get_proj.r @@ -16,24 +16,19 @@ get_proj <- function(projloc=".",geteval=TRUE){ # Read in models and place in result objects - # dir.create(paste0(projloc,"/shinyMixR/app/shinyMixR"),showWarnings = FALSE,recursive = TRUE) - # mdln <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE)) dir.create(paste0(projloc,"/shinyMixR"),showWarnings = FALSE,recursive = TRUE) mdln <- normalizePath(list.files(paste0(projloc,"/models"),pattern="run[[:digit:]]*\\.[r|R]",full.names = TRUE)) mdlnb <- sub("\\.[r|R]","",basename(mdln)) - #sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR/app/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE)) sumres <- normalizePath(list.files(paste0(projloc,"/shinyMixR"),pattern="run[[:digit:]]*\\.ressum\\.rds",full.names = TRUE)) sumresi <- file.info(sumres) summdli <- file.info(mdln) # read in data folder (only in case objects are not yet present) - #datf <- list.files(paste0(projloc,"/shinyMixR/app/data")) datf <- list.files(paste0(projloc,"/data")) grepd <- " |^[[:digit:]]|\\!|\\#|\\$|\\%|\\&|\\'|\\(|\\)|\\-|\\;|\\=|\\@|\\[|\\]|\\^\\`\\{\\|\\}" if(any(grepl(grepd,datf))) warning("Data files with special characters found, take into acount that models that use these can crash") # Read in models and results - #if(!file.exists(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds"))){ if(!file.exists(paste0(projloc,"/shinyMixR/project.rds"))){ mdls <- lapply(mdln,list) names(mdls) <- sub("\\.[r|R]","",basename(mdln)) @@ -42,7 +37,6 @@ get_proj <- function(projloc=".",geteval=TRUE){ }else{ for(i in 1:length(mdln)){ names(mdls[[i]]) <- "model" - #if(geteval) mdls[[i]]$modeleval <- try(eval(parse(text=c("nlmixrUI(",readLines(mdln[i]),")")))) mdls[[i]]$modeleval <- list() if(geteval) mdls[[i]]$modeleval$meta <- try(get_meta(mdln[i])) } @@ -50,11 +44,9 @@ get_proj <- function(projloc=".",geteval=TRUE){ for(i in sumres) mdls[[sub("\\.ressum\\.rds","",basename(i))]]$results <- readRDS(i) mdls$meta <- list(lastrefresh=Sys.time()) }else{ - #mdls <- readRDS(paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds")) mdls <- readRDS(paste0(projloc,"/shinyMixR/project.rds")) # for the list with models, check if new models are available or old models are deleted # and if models are updated after last refresh: - # inproj <- unlist(sapply(mdls[names(mdls)[names(mdls)!="meta"]],"[",1)) inproj <- names(mdls)[names(mdls)!="meta"] todel <- setdiff(tolower(inproj),tolower(mdlnb)) toadd <- setdiff(tolower(mdlnb),tolower(inproj)) @@ -66,7 +58,6 @@ get_proj <- function(projloc=".",geteval=TRUE){ names(mdls2) <- toadd for(i in 1:length(mdls2)){ names(mdls2[[i]]) <- "model" - #if(geteval) mdls2[[i]]$modeleval <- try(eval(parse(text=c("nlmixrUI(",readLines(mdln[which(mdlnb%in%toadd)][i]),")")))) if(geteval) mdls2[[i]]$modeleval$meta <- try(get_meta(mdln[which(mdlnb%in%toadd)][i])) } mdls <- c(mdls,mdls2) @@ -75,7 +66,6 @@ get_proj <- function(projloc=".",geteval=TRUE){ if(geteval){ for(i in mdln){ if(summdli$mtime[row.names(summdli)==i] > mdls$meta$lastrefresh) - #mdls[[sub("\\.[r|R]","",basename(i))]]$modeleval <- try(eval(parse(text=c("nlmixrUI(",readLines(i),")")))) mdls[[sub("\\.[r|R]","",basename(i))]]$modeleval$meta <- try(get_meta(i)) } } @@ -89,9 +79,7 @@ get_proj <- function(projloc=".",geteval=TRUE){ chk <- data.frame(mdl=sub("\\.[r|R]","",basename(mdln)),mdlsv=summdli$mtime,stringsAsFactors = FALSE) chk$ressv <- sumresi$mtime[match(chk$mdl,sub("\\.ressum\\.rds","",basename(sumres)))] chk <- chk[which(chk$mdlsv>chk$ressv),] - #if(nrow(chk)>0) noret <- apply(chk,1,function(x) cat("Be aware that model is saved after results for",x['mdl'],"\n")) - #saveRDS(mdls,file=paste0(projloc,"/shinyMixR/app/shinyMixR/project.rds")) saveRDS(mdls,file=paste0(projloc,"/shinyMixR/project.rds")) return(mdls) } diff --git a/R/gof_plot.r b/R/gof_plot.r index 9d850d6..f4975cc 100644 --- a/R/gof_plot.r +++ b/R/gof_plot.r @@ -87,13 +87,10 @@ gof_plot <- function(dfrm,type="xpose",mdlnm=NULL,colby=NULL,ptype="all",outnm=N return(pl) }else{ if(is.null(mdlnm)) stop("in case output should be saved, mdlnm should be given") - #titl <- cowplot::ggdraw() + cowplot::draw_label(mdlnm, fontface = 'bold', x = 0,hjust = 0) + theme(plot.margin = margin(0, 0, 0, 7)) dir.create(paste0(projloc,"/analysis/",mdlnm),showWarnings=FALSE) if(grepl("\\.tex$",outnm)){ - #R3port::ltx_plot(cowplot::plot_grid(titl,pl,rel_heights = c(0.1, 1),ncol=1),out=paste0(projloc,"/analysis/",mdlnm,"/",basename(outnm)),title="GOF plots",...) R3port::ltx_plot(pl,out=paste0(projloc,"/analysis/",mdlnm,"/",basename(outnm)),title="GOF plots",...) }else if(grepl("\\.html$",outnm)){ - #R3port::html_plot(cowplot::plot_grid(titl,pl,rel_heights = c(0.1, 1),ncol=1),out=paste0(projloc,"/analysis/",mdlnm,"/",basename(outnm)),title="GOF plots",...) R3port::html_plot(pl,out=paste0(projloc,"/analysis/",mdlnm,"/",basename(outnm)),title="GOF plots",...) } } diff --git a/R/module_edit.R b/R/module_edit.R index 318d1d9..bcf2e86 100644 --- a/R/module_edit.R +++ b/R/module_edit.R @@ -111,14 +111,10 @@ module_edit_server <- function(id, r, settings) { observeEvent(input$updinit,{showModal(initmodal())},ignoreInit = TRUE) observeEvent(input$goupdate,{ if(isTruthy(input$finest) && isTruthy(input$tosave)){ - #res <- try(update_inits(input$editor,paste0("shinyMixr/",input$finest,".res.rds"),paste0("models/",input$tosave))) - #cat("getting stuff from",paste0(r$this_wd,"/models/",input$finest,".r"),"with results from",paste0(r$this_wd,"/shinyMixr/",input$finest,".res.rds"), - # "to model",paste0(r$this_wd,"/models/",input$tosave)) res <- try(update_inits(readLines(paste0(r$this_wd,"/models/",input$finest,".r")), paste0(r$this_wd,"/shinyMixr/",input$finest,".res.rds"), paste0(r$this_wd,"/models/",input$tosave))) if("try-error"%in%class(res)){ - #myalert("Could not update initials",type = "error") myalert(res,type = "error") }else{ r$proj_obj <- get_proj(r$this_wd) diff --git a/R/module_gof.R b/R/module_gof.R index 1a76989..fd40b8d 100644 --- a/R/module_gof.R +++ b/R/module_gof.R @@ -24,8 +24,6 @@ module_gof_ui <- function(id, proj_obj) { numericInput(ns("plheight"), "plot height:", 800) ), - # When using a box, the content overflows, also a box does not provide a lot of functionality in this case - # box(width=9, title = "Output",status="lightblue",solidHeader=TRUE,plotOutput(ns("gof_plot")),height="80vh") #,width="80%" ,height="100%" column(9,plotOutput(ns("gof_plot"))) ) ) diff --git a/R/module_overview.R b/R/module_overview.R index 9a8a816..f526a63 100644 --- a/R/module_overview.R +++ b/R/module_overview.R @@ -11,11 +11,9 @@ module_overview_ui <- function(id) { tagList( div(id='buttondiv', class='btn-group', actionButton(ns("overview_refr"), "Refresh",icon=icon("arrows-rotate")), - #actionButton(ns("overview_adpt"), "Adapt model notes",icon=icon("list")), module_metadata_ui(ns("adapt_meta_ov"),"overview"), module_scripts_ui(ns("runscripts")), module_reports_ui(ns("reports")), - #module_metadata_ui(ns("dummy"),"save"), actionButton(ns("hlr"), "Results",icon=icon("file-lines")), actionButton(ns("del"), "Delete model(s)",icon=icon("trash")) ),br(),br(), diff --git a/R/module_partable.R b/R/module_partable.R index 1b4adcf..8a2ca75 100644 --- a/R/module_partable.R +++ b/R/module_partable.R @@ -46,12 +46,9 @@ module_pt_server <- function(id, r) { parTable <- function(inp, projloc, saveit = FALSE){ obj <- get_proj(projloc = projloc) if(!saveit) { - #print(obj) - #print(inp$EstLst) par_table(obj,models=inp$EstLst,bsv=inp$bsv,shrink=inp$shrink,backt=inp$backt,formatting=TRUE) } else { savnm <- ifelse(inp$typePars=="PDF",paste0(inp$namePars,".tex"),paste0(inp$namePars,".html")) - #print(savnm) par_table(obj,models=inp$EstLst,outnm=savnm,show=inp$showPars,projloc=projloc,bsv=inp$bsv,shrink=inp$shrink,backt=inp$backt,formatting=ifelse(inp$typePars=="PDF",FALSE,TRUE)) } } diff --git a/R/module_reports.R b/R/module_reports.R index a7e5e12..6408456 100644 --- a/R/module_reports.R +++ b/R/module_reports.R @@ -23,7 +23,6 @@ module_reports_server <- function(id) { ns <- session$ns modalDialog(title="Reports",easyClose = TRUE,size="l",fade=FALSE, fluidRow( - #column(6,selectInput(ns("models"),"Model(s)",basename(models()),multiple=FALSE,size=15,selectize=FALSE,width='100%')), column(6,selectInput(ns("models"),"Model(s)",list.dirs("analysis",recursive=FALSE,full.names=FALSE),multiple=FALSE,size=15,selectize=FALSE,width='100%')), column(6,selectInput(ns("results"),"Result(s)","",multiple=TRUE,size=15,selectize=FALSE,width='100%')) ), @@ -76,7 +75,6 @@ module_reports_server <- function(id) { } } }else{ - #shinyWidgets::sendSweetAlert(session = session, title="Report",text = "Select folder and results for report" ,type = "error") myalert("Select folder and results for report",type = "error") } }) diff --git a/R/run_nmx.r b/R/run_nmx.r index e1b646a..0914598 100644 --- a/R/run_nmx.r +++ b/R/run_nmx.r @@ -71,8 +71,6 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= }else{ system(paste0(R.home("bin"), "/Rscript \"", tscr, "\" > \"",projloc,"/shinyMixR/temp/",mod,".prog.txt\" 2>&1"),wait=FALSE) } - - # if(autoupdate) assign(dnm,proj,pos = .GlobalEnv) }else{ # Handle subsetting (data is loaded in global environment by get_proj function) if(!is.null(meta$subs) && meta$subs!="") data_nlm <- subset(get(meta$data),eval(parse(text=(meta$subs)))) else data_nlm <- get(meta$data) @@ -87,7 +85,6 @@ run_nmx <- function(mod,proj=proj,ext=TRUE,saverds=TRUE,autoupdate=TRUE,projloc= saveRDS(ressum,file=paste0(projloc,"/shinyMixR/",mod,".ressum.rds")) } proj[[mod]]$results <- ressum - # assign(dnm,proj,pos = .GlobalEnv) return(modres) } } diff --git a/R/run_shinymixr.r b/R/run_shinymixr.r index 59f4dad..396ccab 100644 --- a/R/run_shinymixr.r +++ b/R/run_shinymixr.r @@ -23,38 +23,8 @@ #' } run_shinymixr <- function(wd = getwd(),...){ - #if(!file.exists(paste0(wd,"/shinyMixR/app/www"))) try(dir.create(paste0(wd,"/shinyMixR/app/www"),recursive = TRUE)) - #if(!file.exists(paste0(wd,"/shinyMixR/app/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/app/shinyMixR/temp"),recursive=TRUE)) - #if(!file.exists(paste0(wd,"/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/temp"),recursive=TRUE)) - - #try(file.copy(system.file("dashboard","app.R",package="shinyMixR"), paste0(wd,"/shinyMixR/app/app.R"),overwrite = TRUE),silent = TRUE) - #try(file.copy(system.file("dashboard","www/logoshinyMixR.png",package="shinyMixR"), paste0(wd,"/shinyMixR/app/www/logoshinyMixR.png")),silent = TRUE) - - # Set the working directory so the project can be found - #adpt <- readLines(system.file("dashboard", "app.R", package = "shinyMixR")) - #adpt <- c(paste0("setwd(\"", normalizePath(wd, winslash = "/"), "\")"), adpt) - #writeLines(adpt, paste0(wd,"/shinyMixR/app/app.R")) - - # Clean up stuff before running the app (check if feasible or not) - #try(unlink(list.files(paste0(wd,"/shinyMixR/temp"),pattern=".*prog\\.txt$",full.names = TRUE))) - # if (dry_run == TRUE) { - # return() - # } else { - # shiny::runApp(paste0(wd,"/shinyMixR/app"),...) - # } - #owd <- getwd() - #if(normalizePath(owd)!=normalizePath(wd)) setwd(wd) - #cat("I am in ",getwd(),"\n") - #on.exit(setwd(owd)) - #if(!file.exists("shinyMixR/temp")) try(dir.create("shinyMixR/temp",recursive=TRUE)) if(!file.exists(paste0(wd,"/shinyMixR/temp"))) try(dir.create(paste0(wd,"/shinyMixR/temp"),recursive=TRUE)) proj_obj <- get_proj(wd) - # Check and load nlmixr(2); set nlmixr2 as import so needed when package is loaded and this is also a CRAN warning - # if ("nlmixr2" %in% rownames(installed.packages())){ - # library(nlmixr2) - # } else { - # cat("you need the 'nlmixr2' package to run models\n") - # } newtheme <- fresh::create_theme( theme = "darkly", # theme has no effect, at least within bs4Dash @@ -131,5 +101,4 @@ run_shinymixr <- function(wd = getwd(),...){ }, options = list(launch.browser=TRUE,...) # set general options here for running the app ) - #cat("I was in ",getwd(),"\n") } diff --git a/R/utils.R b/R/utils.R index 86ba81d..dd9ffd7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -19,7 +19,6 @@ setup_shinymixr_test <- function(dir = "./tests/files", overwrite = TRUE, record } create_proj(dir, overwrite = overwrite) - #run_shinymixr(wd = dir, dry_run = TRUE) if(incres){ file.copy(system.file(c("other/run1.res.rds","other/run1.ressum.rds"),package="shinyMixR"),