From 9d8c3c920c0c6d7f02b4fd61d9c66f29788f8efc Mon Sep 17 00:00:00 2001 From: elimillera Date: Mon, 20 Sep 2021 21:39:15 +0000 Subject: [PATCH 1/7] Update for passing build --- .Rbuildignore | 2 ++ DESCRIPTION | 5 ++++- NAMESPACE | 4 ++-- R/_disable_autoload.R | 3 +++ R/app_config.R | 45 +++++++++++++++++++++++++++++++++++++++++++ R/safetyGraphicsApp.R | 6 +++++- app.R | 7 +++++++ inst/golem-config.yml | 8 ++++++++ 8 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 R/_disable_autoload.R create mode 100644 R/app_config.R create mode 100644 app.R create mode 100644 inst/golem-config.yml diff --git a/.Rbuildignore b/.Rbuildignore index ab2f169e..9bb8f9e8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -14,3 +14,5 @@ ^CRAN-RELEASE$ ^customSettings$ ^\.github$ +^app\.R$ +^rsconnect$ diff --git a/DESCRIPTION b/DESCRIPTION index 934c89c8..7b924260 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -52,7 +52,10 @@ Imports: sortable, stringr, yaml, - shinybusy + shinybusy, + pkgload, + golem, + config Remotes: safetyGraphics/safetyCharts VignetteBuilder: knitr Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 432ddc30..c380f8ce 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -52,6 +52,8 @@ import(safetyData) import(shiny) import(yaml) importFrom(DT,renderDT) +importFrom(config,get) +importFrom(golem,with_golem_options) importFrom(listviewer,jsonedit) importFrom(listviewer,jsoneditOutput) importFrom(listviewer,renderJsonedit) @@ -84,5 +86,3 @@ importFrom(stringr,str_to_upper) importFrom(utils,hasName) importFrom(utils,zip) importFrom(yaml,as.yaml) -importFrom(yaml,write_yaml) - diff --git a/R/_disable_autoload.R b/R/_disable_autoload.R new file mode 100644 index 00000000..a8c9436a --- /dev/null +++ b/R/_disable_autoload.R @@ -0,0 +1,3 @@ +# Disabling shiny autoload + +# See ?shiny::loadSupport for more information diff --git a/R/app_config.R b/R/app_config.R new file mode 100644 index 00000000..d19521cc --- /dev/null +++ b/R/app_config.R @@ -0,0 +1,45 @@ +#' Access files in the current app +#' +#' NOTE: If you manually change your package name in the DESCRIPTION, +#' don't forget to change it here too, and in the config file. +#' For a safer name change mechanism, use the `golem::set_golem_name()` function. +#' +#' @param ... character vectors, specifying subdirectory and file(s) +#' within your package. The default, none, returns the root of the app. +#' +#' @importFrom config get +#' +#' @noRd +app_sys <- function(...){ + system.file(..., package = "safetyGraphics") +} + + +#' Read App Config +#' +#' @param value Value to retrieve from the config file. +#' @param config GOLEM_CONFIG_ACTIVE value. If unset, R_CONFIG_ACTIVE. +#' If unset, "default". +#' @param use_parent Logical, scan the parent directory for config file. +#' +#' @noRd +get_golem_config <- function( + value, + config = Sys.getenv( + "GOLEM_CONFIG_ACTIVE", + Sys.getenv( + "R_CONFIG_ACTIVE", + "default" + ) + ), + use_parent = TRUE +){ + config::get( + value = value, + config = config, + # Modify this if your config file is somewhere else: + file = app_sys("golem-config.yml"), + use_parent = use_parent + ) +} + diff --git a/R/safetyGraphicsApp.R b/R/safetyGraphicsApp.R index 8902c97a..c19c4a7e 100644 --- a/R/safetyGraphicsApp.R +++ b/R/safetyGraphicsApp.R @@ -10,6 +10,7 @@ #' #' @import shiny #' @import safetyData +#' @importFrom golem with_golem_options #' #' @export @@ -43,5 +44,8 @@ safetyGraphicsApp <- function( ) } ) - runApp(app, launch.browser = TRUE) + with_golem_options( + app = app, golem_opts = NULL + ) + #runApp(app) } diff --git a/app.R b/app.R new file mode 100644 index 00000000..acf01d28 --- /dev/null +++ b/app.R @@ -0,0 +1,7 @@ +# Launch the ShinyApp (Do not remove this comment) +# To deploy, run: rsconnect::deployApp() +# Or use the blue button on top of this file +library(golem) +pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE) +options( "golem.app.prod" = TRUE) +safetyGraphics::safetyGraphicsApp() # add parameters here (if any) diff --git a/inst/golem-config.yml b/inst/golem-config.yml new file mode 100644 index 00000000..0d9e06fc --- /dev/null +++ b/inst/golem-config.yml @@ -0,0 +1,8 @@ +default: + golem_name: safetyGraphics + golem_version: 2.0.0 + app_prod: no +production: + app_prod: yes +dev: + golem_wd: !expr here::here() From 2dcf258fc302229b5316a96c1f9e10f5bf4566f7 Mon Sep 17 00:00:00 2001 From: elimillera Date: Thu, 30 Sep 2021 13:58:15 +0000 Subject: [PATCH 2/7] Remove golem deps --- DESCRIPTION | 7 ++----- NAMESPACE | 2 -- R/app_config.R | 45 ---------------------------------------- R/safetyGraphicsApp.R | 13 ++++++------ app.R | 4 +--- inst/golem-config.yml | 8 ------- man/safetyGraphicsApp.Rd | 3 ++- 7 files changed, 12 insertions(+), 70 deletions(-) delete mode 100644 R/app_config.R delete mode 100644 inst/golem-config.yml diff --git a/DESCRIPTION b/DESCRIPTION index 7b924260..27ae0f84 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ Depends: R (>= 3.5) License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 Suggests: fs, ggplot2, @@ -52,10 +52,7 @@ Imports: sortable, stringr, yaml, - shinybusy, - pkgload, - golem, - config + shinybusy Remotes: safetyGraphics/safetyCharts VignetteBuilder: knitr Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index c380f8ce..ba3befaa 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -52,8 +52,6 @@ import(safetyData) import(shiny) import(yaml) importFrom(DT,renderDT) -importFrom(config,get) -importFrom(golem,with_golem_options) importFrom(listviewer,jsonedit) importFrom(listviewer,jsoneditOutput) importFrom(listviewer,renderJsonedit) diff --git a/R/app_config.R b/R/app_config.R deleted file mode 100644 index d19521cc..00000000 --- a/R/app_config.R +++ /dev/null @@ -1,45 +0,0 @@ -#' Access files in the current app -#' -#' NOTE: If you manually change your package name in the DESCRIPTION, -#' don't forget to change it here too, and in the config file. -#' For a safer name change mechanism, use the `golem::set_golem_name()` function. -#' -#' @param ... character vectors, specifying subdirectory and file(s) -#' within your package. The default, none, returns the root of the app. -#' -#' @importFrom config get -#' -#' @noRd -app_sys <- function(...){ - system.file(..., package = "safetyGraphics") -} - - -#' Read App Config -#' -#' @param value Value to retrieve from the config file. -#' @param config GOLEM_CONFIG_ACTIVE value. If unset, R_CONFIG_ACTIVE. -#' If unset, "default". -#' @param use_parent Logical, scan the parent directory for config file. -#' -#' @noRd -get_golem_config <- function( - value, - config = Sys.getenv( - "GOLEM_CONFIG_ACTIVE", - Sys.getenv( - "R_CONFIG_ACTIVE", - "default" - ) - ), - use_parent = TRUE -){ - config::get( - value = value, - config = config, - # Modify this if your config file is somewhere else: - file = app_sys("golem-config.yml"), - use_parent = use_parent - ) -} - diff --git a/R/safetyGraphicsApp.R b/R/safetyGraphicsApp.R index c19c4a7e..fcc151c6 100644 --- a/R/safetyGraphicsApp.R +++ b/R/safetyGraphicsApp.R @@ -10,7 +10,6 @@ #' #' @import shiny #' @import safetyData -#' @importFrom golem with_golem_options #' #' @export @@ -25,7 +24,8 @@ safetyGraphicsApp <- function( mapping=NULL, autoMapping=TRUE, filterDomain="dm", - chartSettingsPaths = NULL + chartSettingsPaths = NULL, + run_now = TRUE ){ message("Initializing safetyGraphicsApp") config <- app_startup(domainData, meta, charts, mapping, autoMapping, filterDomain, chartSettingsPaths) @@ -44,8 +44,9 @@ safetyGraphicsApp <- function( ) } ) - with_golem_options( - app = app, golem_opts = NULL - ) - #runApp(app) + + if(run_now) + runApp(app) + else + app } diff --git a/app.R b/app.R index acf01d28..ed5fad1e 100644 --- a/app.R +++ b/app.R @@ -1,7 +1,5 @@ # Launch the ShinyApp (Do not remove this comment) # To deploy, run: rsconnect::deployApp() # Or use the blue button on top of this file -library(golem) pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE) -options( "golem.app.prod" = TRUE) -safetyGraphics::safetyGraphicsApp() # add parameters here (if any) +safetyGraphics::safetyGraphicsApp(run_now = FALSE) # add parameters here (if any) diff --git a/inst/golem-config.yml b/inst/golem-config.yml deleted file mode 100644 index 0d9e06fc..00000000 --- a/inst/golem-config.yml +++ /dev/null @@ -1,8 +0,0 @@ -default: - golem_name: safetyGraphics - golem_version: 2.0.0 - app_prod: no -production: - app_prod: yes -dev: - golem_wd: !expr here::here() diff --git a/man/safetyGraphicsApp.Rd b/man/safetyGraphicsApp.Rd index 85610cb0..a3f5eed7 100644 --- a/man/safetyGraphicsApp.Rd +++ b/man/safetyGraphicsApp.Rd @@ -12,7 +12,8 @@ safetyGraphicsApp( mapping = NULL, autoMapping = TRUE, filterDomain = "dm", - chartSettingsPaths = NULL + chartSettingsPaths = NULL, + run_now = TRUE ) } \arguments{ From 4965122545b2cde36145516c4fb521026b69a378 Mon Sep 17 00:00:00 2001 From: elimillera Date: Fri, 8 Oct 2021 00:33:07 +0000 Subject: [PATCH 3/7] update run_now to runNow --- R/safetyGraphicsApp.R | 7 ++++--- app.R | 2 +- man/safetyGraphicsApp.Rd | 4 +++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/R/safetyGraphicsApp.R b/R/safetyGraphicsApp.R index fcc151c6..ed75fbd1 100644 --- a/R/safetyGraphicsApp.R +++ b/R/safetyGraphicsApp.R @@ -6,7 +6,8 @@ #' @param mapping list specifying the initial mapping values for each data mapping for each domain (e.g. list(aes= list(id_col='USUBJID', seq_col='AESEQ')). #' @param autoMapping boolean indicating whether the app should attempt to automatically detect data standards and generate mappings for the data provided. Values specified in the `mapping` parameter overwrite automatically generated mappings when both are found. Defaults to true. #' @param filterDomain domain used for the data/filter tab. Demographics ("`dm`") is used by default. Using a domain that is not one record per participant is not recommended. -#' @param chartSettingsPaths path(s) where customization functions are saved relative to your working directory. All charts can have itialization (e.g. myChart_Init.R) and static charts can have charting functions (e.g. myGraphic_Chart.R). All R files in this folder are sourced and files with the correct naming convention are linked to the chart. See the Custom Charts vignette for more details. +#' @param chartSettingsPaths path(s) where customization functions are saved relative to your working directory. All charts can have itialization (e.g. myChart_Init.R) and static charts can have charting functions (e.g. myGraphic_Chart.R). All R files in this folder are sourced and files with the correct naming convention are linked to the chart. See the Custom Charts vignette for more details. +#' @param runNow Should the shiny app object created be run directly? Helpful when writing functions to dispatch to shinyapps, rsconnect, or shinyproxy. #' #' @import shiny #' @import safetyData @@ -25,7 +26,7 @@ safetyGraphicsApp <- function( autoMapping=TRUE, filterDomain="dm", chartSettingsPaths = NULL, - run_now = TRUE + runNow = TRUE ){ message("Initializing safetyGraphicsApp") config <- app_startup(domainData, meta, charts, mapping, autoMapping, filterDomain, chartSettingsPaths) @@ -45,7 +46,7 @@ safetyGraphicsApp <- function( } ) - if(run_now) + if(runNow) runApp(app) else app diff --git a/app.R b/app.R index ed5fad1e..5f177150 100644 --- a/app.R +++ b/app.R @@ -2,4 +2,4 @@ # To deploy, run: rsconnect::deployApp() # Or use the blue button on top of this file pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE) -safetyGraphics::safetyGraphicsApp(run_now = FALSE) # add parameters here (if any) +safetyGraphics::safetyGraphicsApp(runNow = FALSE) # add parameters here (if any) diff --git a/man/safetyGraphicsApp.Rd b/man/safetyGraphicsApp.Rd index a3f5eed7..84f1e383 100644 --- a/man/safetyGraphicsApp.Rd +++ b/man/safetyGraphicsApp.Rd @@ -13,7 +13,7 @@ safetyGraphicsApp( autoMapping = TRUE, filterDomain = "dm", chartSettingsPaths = NULL, - run_now = TRUE + runNow = TRUE ) } \arguments{ @@ -30,6 +30,8 @@ safetyGraphicsApp( \item{filterDomain}{domain used for the data/filter tab. Demographics ("\code{dm}") is used by default. Using a domain that is not one record per participant is not recommended.} \item{chartSettingsPaths}{path(s) where customization functions are saved relative to your working directory. All charts can have itialization (e.g. myChart_Init.R) and static charts can have charting functions (e.g. myGraphic_Chart.R). All R files in this folder are sourced and files with the correct naming convention are linked to the chart. See the Custom Charts vignette for more details.} + +\item{runNow}{Should the shiny app object created be run directly? Helpful when writing functions to dispatch to shinyapps, rsconnect, or shinyproxy.} } \description{ Run the interactive safety graphics app From 1cf459e0dee79d5b5e1fc46d08f77ceb63578dd0 Mon Sep 17 00:00:00 2001 From: Jeremy Wildfire Date: Tue, 12 Oct 2021 21:50:00 -0400 Subject: [PATCH 4/7] update version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f1ca0619..62404abc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: safetyGraphics Title: Interactive Graphics for Monitoring Clinical Trial Safety -Version: 2.0.1 +Version: 2.1.0 Authors@R: c( person("Jeremy", "Wildfire", email = "jwildfire@gmail.com", role = c("cre","aut")), person("Becca", "Krouse", role="aut"), From 1bf63a7b8752c18edbc3f36a120341298f46c268 Mon Sep 17 00:00:00 2001 From: Jeremy Wildfire Date: Tue, 9 Nov 2021 13:37:24 -0500 Subject: [PATCH 5/7] use system.file() to load css. #651 --- NAMESPACE | 1 + R/mod_safetyGraphicsUI.R | 12 ++++-------- man/safetyGraphicsApp.Rd | 1 - 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index e8937fc7..0503b39e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -52,6 +52,7 @@ import(safetyData) import(shiny) import(yaml) importFrom(DT,renderDT) +importFrom(devtools,system.file) importFrom(purrr,keep) importFrom(purrr,map) importFrom(purrr,map2) diff --git a/R/mod_safetyGraphicsUI.R b/R/mod_safetyGraphicsUI.R index 02f5dc6e..386981f6 100644 --- a/R/mod_safetyGraphicsUI.R +++ b/R/mod_safetyGraphicsUI.R @@ -8,20 +8,16 @@ #' @param standards a list of information regarding data standards. Each list item should use the format returned by safetyGraphics::detectStandard. #' #' @importFrom shinyjs useShinyjs +#' @importFrom devtools system.file #' #' @export safetyGraphicsUI <- function(id, meta, domainData, mapping, standards){ #read css from pacakge ns<-NS(id) - app_css <- NULL - for(lib in .libPaths()){ - if(is.null(app_css)){ - css_path <- paste(lib,'safetyGraphics', 'www','index.css', sep="/") - if(file.exists(css_path)) app_css <- HTML(readLines(css_path)) - } - } - + css_path <- system.file("www","index.css", package = "safetyGraphics") + app_css <- HTML(readLines(css_path)) + #script to append population badge nav bar participant_badge<-tags$script( HTML( diff --git a/man/safetyGraphicsApp.Rd b/man/safetyGraphicsApp.Rd index 565bd468..20251721 100644 --- a/man/safetyGraphicsApp.Rd +++ b/man/safetyGraphicsApp.Rd @@ -32,7 +32,6 @@ safetyGraphicsApp( \item{chartSettingsPaths}{path(s) where customization functions are saved relative to your working directory. All charts can have initialization (e.g. myChart_Init.R) and static charts can have charting functions (e.g. myGraphic_Chart.R). All R files in this folder are sourced and files with the correct naming convention are linked to the chart. See the Custom Charts vignette for more details.} \item{runNow}{Should the shiny app object created be run directly? Helpful when writing functions to dispatch to shinyapps, rsconnect, or shinyproxy.} - } \description{ Run the core safetyGraphics App From 92f919a2a5f32108b37a2f8ac2786c40ad88ce1c Mon Sep 17 00:00:00 2001 From: Jeremy Wildfire Date: Tue, 9 Nov 2021 13:55:36 -0500 Subject: [PATCH 6/7] update docs --- NAMESPACE | 1 - R/makeChartConfig.R | 19 ++++++++----------- R/mod_safetyGraphicsUI.R | 4 ++-- R/safetyGraphicsInit.R | 10 ++-------- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 0503b39e..e8937fc7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -52,7 +52,6 @@ import(safetyData) import(shiny) import(yaml) importFrom(DT,renderDT) -importFrom(devtools,system.file) importFrom(purrr,keep) importFrom(purrr,map) importFrom(purrr,map2) diff --git a/R/makeChartConfig.R b/R/makeChartConfig.R index bba374a5..4f615b2c 100644 --- a/R/makeChartConfig.R +++ b/R/makeChartConfig.R @@ -34,17 +34,14 @@ makeChartConfig <- function(dirs, packages="safetyCharts", packageLocation="conf if(!is.null(packages)){ for(package in packages){ packageFound<-FALSE - for(lib in .libPaths()){ - - packageDir<-paste(lib,package,packageLocation, sep="/") - if(file.exists(packageDir)) { - loaded <- do.call(require,list(package)) - if(!loaded) do.call(library,list(package)) #Attach the library to the search list if it is installed - message("- Found the {",package,"} package and added ", packageDir," to list of chart locations.") - packageFound<-TRUE - dirs<-c(dirs, packageDir) - break - } + packageDir <- system.file(packageLocation, package = package) + if(file.exists(packageDir)) { + loaded <- do.call(require,list(package)) + if(!loaded) do.call(library,list(package)) #Attach the library to the search list if it is installed + message("- Found the {",package,"} package and added ", packageDir," to list of chart locations.") + packageFound<-TRUE + dirs<-c(dirs, packageDir) + break } if(!packageFound){ message("{",package, "} package not found or '",packageLocation,"' folder does not exist, please install package and confirm that specified folder is found.") diff --git a/R/mod_safetyGraphicsUI.R b/R/mod_safetyGraphicsUI.R index 386981f6..c810437f 100644 --- a/R/mod_safetyGraphicsUI.R +++ b/R/mod_safetyGraphicsUI.R @@ -8,13 +8,13 @@ #' @param standards a list of information regarding data standards. Each list item should use the format returned by safetyGraphics::detectStandard. #' #' @importFrom shinyjs useShinyjs -#' @importFrom devtools system.file #' #' @export safetyGraphicsUI <- function(id, meta, domainData, mapping, standards){ - #read css from pacakge ns<-NS(id) + + #read css from package css_path <- system.file("www","index.css", package = "safetyGraphics") app_css <- HTML(readLines(css_path)) diff --git a/R/safetyGraphicsInit.R b/R/safetyGraphicsInit.R index 7c136424..b5927804 100644 --- a/R/safetyGraphicsInit.R +++ b/R/safetyGraphicsInit.R @@ -21,14 +21,8 @@ safetyGraphicsInit <- function(charts=makeChartConfig(), delayTime=1000, maxFile } } - - app_css <- NULL - for(lib in .libPaths()){ - if(is.null(app_css)){ - css_path <- paste(lib,'safetyGraphics', 'www','index.css', sep="/") - if(file.exists(css_path)) app_css <- HTML(readLines(css_path)) - } - } + css_path <- system.file("www","index.css", package = "safetyGraphics") + app_css <- HTML(readLines(css_path)) ui<-fluidPage( useShinyjs(), From f730ff38459c74b83837be560566e3d1aa83aaef Mon Sep 17 00:00:00 2001 From: jwildfire Date: Thu, 18 Nov 2021 02:44:03 +0000 Subject: [PATCH 7/7] move app.r to /inst --- app.R => inst/deploy/app.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename app.R => inst/deploy/app.R (73%) diff --git a/app.R b/inst/deploy/app.R similarity index 73% rename from app.R rename to inst/deploy/app.R index 5f177150..7451bed1 100644 --- a/app.R +++ b/inst/deploy/app.R @@ -1,5 +1,5 @@ # Launch the ShinyApp (Do not remove this comment) # To deploy, run: rsconnect::deployApp() # Or use the blue button on top of this file -pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE) +library(safetyGraphics) # or use devtools::install_github() to load dev version safetyGraphics::safetyGraphicsApp(runNow = FALSE) # add parameters here (if any)