R/safetyGraphicsApp.R

Defines functions safetyGraphicsApp

Documented in safetyGraphicsApp

#' Run the core safetyGraphics App
#'
#' @param domainData named list of data.frames to be loaded in to the app. Sample AdAM data from the safetyData package used by default
#' @param meta data frame containing the metadata for use in the app. If no metadata is provided, metatdata is generated by `makeMeta()`. 
#' @param charts list of charts in the format produced by safetyGraphics::makeChartConfig()
#' @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 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
#' 
#' @export

safetyGraphicsApp <- function(
  domainData=list(
    labs=safetyData::adam_adlbc, 
    aes=safetyData::adam_adae, 
    dm=safetyData::adam_adsl
  ),
  meta = NULL, 
  charts=NULL,
  mapping=NULL,
  autoMapping=TRUE,
  filterDomain="dm",
  chartSettingsPaths = NULL,
  runNow = TRUE
){
  message("Initializing safetyGraphicsApp")
  config <- app_startup(domainData, meta, charts, mapping, autoMapping, filterDomain, chartSettingsPaths)

  app <- shinyApp(
    ui =  safetyGraphicsUI("sg",config$meta, config$domainData, config$mapping, config$standards),
    server = function(input,output,session){
      callModule(
        safetyGraphicsServer,
        "sg",
        config$meta, 
        config$mapping, 
        config$domainData, 
        config$charts, 
        config$filterDomain
      )
    }
  )
  
  if(runNow)
    runApp(app)
  else
    app
}

Try the safetyGraphics package in your browser

Any scripts or data that you put into this service are public.

safetyGraphics documentation built on Dec. 28, 2022, 1:58 a.m.