diff --git a/.Rbuildignore b/.Rbuildignore index 893b8fef..57dc6c86 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -14,4 +14,7 @@ ^CRAN-RELEASE$ ^customSettings$ ^\.github$ +^app\.R$ +^rsconnect$ ^LICENSE\.md$ + 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"), 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/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 02f5dc6e..c810437f 100644 --- a/R/mod_safetyGraphicsUI.R +++ b/R/mod_safetyGraphicsUI.R @@ -12,16 +12,12 @@ #' @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)) - } - } - + + #read css from package + 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/R/safetyGraphicsApp.R b/R/safetyGraphicsApp.R index 024e922c..d918ea2d 100644 --- a/R/safetyGraphicsApp.R +++ b/R/safetyGraphicsApp.R @@ -7,6 +7,7 @@ #' @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 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. +#' @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 @@ -24,7 +25,8 @@ safetyGraphicsApp <- function( mapping=NULL, autoMapping=TRUE, filterDomain="dm", - chartSettingsPaths = NULL + chartSettingsPaths = NULL, + runNow = TRUE ){ message("Initializing safetyGraphicsApp") config <- app_startup(domainData, meta, charts, mapping, autoMapping, filterDomain, chartSettingsPaths) @@ -43,5 +45,9 @@ safetyGraphicsApp <- function( ) } ) - runApp(app, launch.browser = TRUE) + + if(runNow) + runApp(app) + else + app } 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(), diff --git a/inst/deploy/app.R b/inst/deploy/app.R new file mode 100644 index 00000000..7451bed1 --- /dev/null +++ b/inst/deploy/app.R @@ -0,0 +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(safetyGraphics) # or use devtools::install_github() to load dev version +safetyGraphics::safetyGraphicsApp(runNow = FALSE) # add parameters here (if any) diff --git a/man/safetyGraphicsApp.Rd b/man/safetyGraphicsApp.Rd index f5bf3615..20251721 100644 --- a/man/safetyGraphicsApp.Rd +++ b/man/safetyGraphicsApp.Rd @@ -12,7 +12,8 @@ safetyGraphicsApp( mapping = NULL, autoMapping = TRUE, filterDomain = "dm", - chartSettingsPaths = NULL + chartSettingsPaths = NULL, + runNow = TRUE ) } \arguments{ @@ -29,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 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