diff --git a/DESCRIPTION b/DESCRIPTION index 5f73fad9..a0df242a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,7 @@ Depends: R (>= 4.0) License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 Suggests: ggplot2 (>= 3.3.0), knitr (>= 1.34), diff --git a/R/app_startup.R b/R/app_startup.R index 0f23cc26..5d39ca74 100644 --- a/R/app_startup.R +++ b/R/app_startup.R @@ -9,7 +9,9 @@ #' @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 appName character string defining the name of the app (default = "safetyGraphics") +#' @param hexPath path to image file with a hex or other logo. safetyGraphics hex used by default. +#' @param homeTabPath path to html content to be used on the home page. default is a summary of the safetyGraphics framework. #' #' @return List of elements for used to initialize the shiny app with the following parameters #' \itemize{ @@ -21,7 +23,13 @@ #' } #' #' @export -app_startup<-function(domainData=NULL, meta=NULL, charts=NULL, mapping=NULL, autoMapping=NULL, filterDomain=NULL, chartSettingsPaths=NULL){ +app_startup<-function(domainData=NULL, meta=NULL, charts=NULL, mapping=NULL, autoMapping=NULL, filterDomain=NULL, chartSettingsPaths=NULL, appName=NULL, hexPath=NULL, homeTabPath=NULL){ + + # Set defaults for app name, hex and home page content. + if (!is.character(appName)) appName <- 'safetyGraphics' + if (!is.character(hexPath) || !file.exists(hexPath)) hexPath <- system.file("resources/safetyGraphicsHex.png", package = "safetyGraphics") + if (!is.character(homeTabPath) || !file.exists(homeTabPath)) homeTabPath <- system.file('resources/safetyGraphicsHomeTab.html', package = 'safetyGraphics') + # If charts are not provided, load them from chartSettingsPath or the safetyCharts package if(is.null(charts)){ if(is.null(chartSettingsPaths)){ @@ -81,8 +89,11 @@ app_startup<-function(domainData=NULL, meta=NULL, charts=NULL, mapping=NULL, aut domainData=domainData, mapping=mappingObj$mapping, standards=mappingObj$standard, - filterDomain=filterDomain + filterDomain=filterDomain, + appName=appName, + hexPath=hexPath, + homeTabPath = homeTabPath ) return(config) -} \ No newline at end of file +} diff --git a/R/mod_homeTab.R b/R/mod_homeTab.R index 06f83ede..d942bd4e 100644 --- a/R/mod_homeTab.R +++ b/R/mod_homeTab.R @@ -4,11 +4,11 @@ #' #' @export -homeTabUI <- function(id){ +homeTabUI <- function(id) { ns <- NS(id) fluidRow( - column(width=8, style='font-size:20px', uiOutput(outputId = ns("about"))), - column(width=4, imageOutput(outputId = ns("hex"))) + column(width=9, style='font-size:20px', uiOutput(outputId = ns("about"))), + column(width=3, imageOutput(outputId = ns("hex"))) ) } @@ -20,40 +20,20 @@ homeTabUI <- function(id){ #' #' @export -homeTab <- function(input, output, session){ +homeTab <- function(input, output, session, config) { ns <- session$ns - output$about <- renderUI({ - HTML(' -

Welcome to the Safety Graphics Shiny App

-

- The Safety Graphics Shiny app is an interactive tool for evaluating clinical trial safety using a flexible data pipeline. - This application and corresponding {safetyGraphics} R package have been developed as part of the Interactive Safety Graphics (ISG) workstream of the ASA Biopharm-DIA Safety Working Group. -

- -

Using the app

-

- Detailed instructions about using the app can be found in our vignette. - In short, the user will initialize the app with their data, adjust settings as needed, and view the interactive charts. - Finally, the user may export a self-contained, fully reproducible snapshot of the charts that can be easily shared with others. -

-

Charts

-

- The app is built to support a wide variety of chart types including static plots (e.g. from {ggplot2}), shiny modules, {htmlwidgets} and even static outputs like RTFs. - Several pre-configured charts are included in the companion {safetyCharts} R Package, and are available by default in the app. - Other charts can be added using the process descibed in this vignette. -

- -

- For more information about {safetyGraphics}, please visit our GitHub repository. - We also welcome your suggestions in our issue tracker. -

- ') + output$about <- renderUI({ + HTML(readLines(config$homeTabPath)) }) - - output$hex <- renderImage({ - list( - src = system.file("safetyGraphicsHex/safetyGraphicsHex.png", package = "safetyGraphics"), width="60%") - }, deleteFile = FALSE + + output$hex <- renderImage( + { + list( + src = config$hexPath, + width = "100%" + ) + }, + deleteFile = FALSE ) } diff --git a/R/mod_safetyGraphicsServer.R b/R/mod_safetyGraphicsServer.R index 0d7e4b85..2206fcb1 100644 --- a/R/mod_safetyGraphicsServer.R +++ b/R/mod_safetyGraphicsServer.R @@ -18,7 +18,17 @@ #' #' @export -safetyGraphicsServer <- function(input, output, session, meta, mapping, domainData, charts, filterDomain){ +safetyGraphicsServer <- function( + input, + output, + session, + meta, + mapping, + domainData, + charts, + filterDomain, + config +) { #Initialize modules current_mapping<-callModule(mappingTab, "mapping", meta, domainData) @@ -31,7 +41,7 @@ safetyGraphicsServer <- function(input, output, session, meta, mapping, domainDa current_mapping=current_mapping ) - callModule(homeTab, "home") + callModule(homeTab, "home", config) #Initialize Chart UI - Adds subtabs to chart menu - this initializes initializes chart UIs charts %>% purrr::map(~chartsNav(.x,session$ns)) diff --git a/R/mod_safetyGraphicsUI.R b/R/mod_safetyGraphicsUI.R index 523b0a22..c6f7d510 100644 --- a/R/mod_safetyGraphicsUI.R +++ b/R/mod_safetyGraphicsUI.R @@ -11,7 +11,7 @@ #' #' @export -safetyGraphicsUI <- function(id, meta, domainData, mapping, standards){ +safetyGraphicsUI <- function(id, meta, domainData, mapping, standards, config) { ns<-NS(id) #read css from package @@ -50,9 +50,9 @@ safetyGraphicsUI <- function(id, meta, domainData, mapping, standards){ ) ), navbarPage( - "safetyGraphics", + config$appName, id=ns("safetyGraphicsApp"), - tabPanel("Home", icon=icon("home"),homeTabUI(ns("home"))), + tabPanel("Home", icon=icon("home"), homeTabUI(ns("home"))), tabPanel("Mapping", icon=icon("map"), mappingTabUI(ns("mapping"), meta, domainData, mapping, standards)), tabPanel("Filtering", icon=icon("filter"), filterTabUI(ns("filter"))), navbarMenu('Charts', icon=icon("chart-bar")), diff --git a/R/safetyGraphicsApp.R b/R/safetyGraphicsApp.R index 9ba1a102..493ea701 100644 --- a/R/safetyGraphicsApp.R +++ b/R/safetyGraphicsApp.R @@ -7,6 +7,10 @@ #' @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 appName character string defining the name of the app (default = "safetyGraphics") +#' @param hexPath path to image file with a hex or other logo. safetyGraphics hex used by default. +#' @param homeTabPath path to html content to be used on the home page. default is a summary of the safetyGraphics framework. +#' @param launchBrowser boolean indicating whether to launch the app in a browser. default is false #' @param runNow Should the shiny app object created be run directly? Helpful when writing functions to dispatch to shinyapps, rsconnect, or shinyproxy. #' #' @import shiny @@ -15,25 +19,48 @@ #' @export safetyGraphicsApp <- function( - domainData=list( - labs=safetyData::adam_adlbc, - aes=safetyData::adam_adae, - dm=safetyData::adam_adsl + domainData = list( + labs = safetyData::adam_adlbc, + aes = safetyData::adam_adae, + dm = safetyData::adam_adsl ), meta = NULL, - charts=NULL, - mapping=NULL, - autoMapping=TRUE, - filterDomain="dm", + charts = NULL, + mapping = NULL, + autoMapping = TRUE, + filterDomain = "dm", chartSettingsPaths = NULL, + appName = 'safetyGraphics', + hexPath = system.file("resources/safetyGraphicsHex.png", package = "safetyGraphics"), + homeTabPath = system.file('resources/safetyGraphicsHomeTab.html', package = 'safetyGraphics'), + launchBrowser = FALSE, runNow = TRUE ){ message("Initializing safetyGraphicsApp") - config <- app_startup(domainData, meta, charts, mapping, autoMapping, filterDomain, chartSettingsPaths) + + config <- app_startup( + domainData=domainData, + meta=meta, + charts=charts, + mapping=mapping, + autoMapping=autoMapping, + filterDomain=filterDomain, + chartSettingsPaths=chartSettingsPaths, + appName=appName, + hexPath=hexPath, + homeTabPath=homeTabPath + ) app <- shinyApp( - ui = safetyGraphicsUI("sg",config$meta, config$domainData, config$mapping, config$standards), - server = function(input,output,session){ + ui = safetyGraphicsUI( + "sg", + config$meta, + config$domainData, + config$mapping, + config$standards, + config + ), + server = function(input, output, session) { callModule( safetyGraphicsServer, "sg", @@ -41,13 +68,19 @@ safetyGraphicsApp <- function( config$mapping, config$domainData, config$charts, - config$filterDomain + config$filterDomain, + config ) } ) - - if(runNow) - runApp(app) - else - app + + if (runNow) { + if (launchBrowser == TRUE) { + runApp(app, launch.browser = TRUE) + } else { + runApp(app) + } + } + + app } diff --git a/README.md b/README.md index 0253c04d..fcf7db55 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![R build status](https://www.github.com/safetyGraphics/safetyGraphics/workflows/R-CMD-check-main/badge.svg)](https://github.com/SafetyGraphics/safetyGraphics/actions) -# safetyGraphics: Clinical Trial Monitoring with R +# safetyGraphics: Clinical Trial Monitoring with R The {safetyGraphics} package provides a framework for evaluating of clinical trial safety in R using a flexible data pipeline. The package includes a shiny application that allows users to explore safety data using a series of interactive graphics, including the hepatic safety explorer shown below. The package has been developed as part of the Interactive Safety Graphics (ISG) workstream of the ASA Biopharm-DIA Safety Working Group. diff --git a/docs/index.html b/docs/index.html index 08e33b9b..65dd2923 100644 --- a/docs/index.html +++ b/docs/index.html @@ -95,7 +95,7 @@

R build status

-