Skip to contents

Takes figures created using the make figure functions and appends those figures to the specified report. While it takes all report types, it should act as a pass through for "xlsx"

Usage

nca_append_report_figs(
  rpt = NULL,
  mfres = list(),
  rpttype = "docx",
  fig_id = paste0("fig_", abs(rnorm(1))),
  fig_desc = "Description of figure",
  fig_height = 7,
  fig_width = 6,
  fig_start = c(0.07, 0.3),
  fig_stop = c(0.93, 0.99),
  text_format = "text",
  caption_single = "A figure.",
  caption_multiple = "Figure ===FIGNUM=== of ===FIGTOT===.",
  title_single = "A figure title.",
  title_multiple = "A figure title ===FIGNUM=== of ===FIGTOT===.",
  sub_title_single = "Figure sub titles.",
  sub_title_multiple = "Figure sub titles ===FIGNUM=== of ===FIGTOT===.",
  flag_map = list()
)

Arguments

rpt

Reporting object (onbrand object for "pptx" and "docx" rpttypes and a list for "xlsx")

mfres

Output from make figure functions (e.g. mk_figure_ind_obs())

rpttype

Type of report either ("docx" (default), "pptx", or "xlsx")

fig_id

Unique figure ID

fig_desc

Verbose description of the figure

fig_height

Word report figure height in inches (7)

fig_width

Word report figure width in inches (6)

fig_start

In PowerPoint the x and y locations to start relateive to the upper left of the slide.

fig_stop

In PowerPoint the x and y locations to stop relateive to the upper left of the slide.

text_format

How to format text ("md" for markdown or "text" for regular text (default))

caption_single

Caption for a single figure

caption_multiple

Caption for a multiple figures with optional placeholders for the total number of figures (===FIGTOT===) and the current figure number (===FIGNUM===).

title_single

Title for a single figure

title_multiple

title for a multiple figures with optional placeholders for the total number of figures (===FIGTOT===) and the current figure number (===FIGNUM===).

sub_title_single

Title for a single figure

sub_title_multiple

title for a multiple figures with optional placeholders for the total number of figures (===FIGTOT===) and the current figure number (===FIGNUM===).

flag_map

List with flag mapping details.

Value

list with the following elements

  • isgood: Boolean indicating the exit status of the function.

  • msgs: Messages to be passed back to the user.

  • obnd: Report with tables added.

Examples

if(interactive()){
# original file: inst/templates/ruminate.R
library(formods)
library(ruminate)

# These are suggested packages
library(shinydashboard)
#library(ggpubr)
#library(plotly)
#library(shinybusy)
library(prompter)
#library(utils)

tags$style("@import url(https://use.fontawesome.com/releases/v6.4.0/css/all.css);")

# You can copy these locally and customize them for your own needs. Simply
# change the assignment to the local copy you've modified.
formods.yaml  = system.file(package="formods",  "templates",  "formods.yaml")
ASM.yaml      = system.file(package="formods",  "templates",  "ASM.yaml")
UD.yaml       = system.file(package="formods",  "templates",  "UD.yaml")
DW.yaml       = system.file(package="formods",  "templates",  "DW.yaml")
FG.yaml       = system.file(package="formods",  "templates",  "FG.yaml")
NCA.yaml      = system.file(package="ruminate", "templates",  "NCA.yaml")


# Name of  file to indicate we need to load testing data
ftmptest = file.path(tempdir(), "ruminate.test")


# Making sure that the deployed object is created
if(!exists("deployed")){
  deployed = FALSE
}

# If the DEPLOYED file marker existrs we set deployed to TRUE
if(file.exists("DEPLOYED")){
  deployed = TRUE
}

# # Making sure that the run_dev object is created
# if(file.exists(file.path(tempdir(), "RUMINTE_DEVELOPMENT"))){
#   run_dev  = TRUE
# }else{
#   run_dev  = FALSE
# }

# If the SETUP.R file exists we source it
if(file.exists("SETUP.R")){
  source("SETUP.R")
}



CSS <- "
.wrapfig {
  float: right;
  shape-margin: 20px;
  margin-right: 20px;
  margin-bottom: 20px;
}
"

#https://fontawesome.com/icons?from=io
logo_url =
  "https://raw.githubusercontent.com/john-harrold/ruminate/main/man/figures/logo.png"
data_url =
  "https://github.com/john-harrold/formods/raw/master/inst/test_data/TEST_DATA.xlsx"
run_url  =
  "https://runruminate.ubiquity.tools/"
use_url  =
  "https://useruminate.ubiquity.tools/"
main_url =
  "https://ruminate.ubiquity.tools/"
issue_url =
  "https://github.com/john-harrold/ruminate/issues"

intro_text = tags$p(
"Ruminate is a shiny module for pharmacometric data processing,
visualization, and analysis. It consists of separate shiny modules that
provide interfaces into common R packages and provides the underlying code.
This is done to facilitate usage of those packages and to provide reproducible
analyses." ,
tags$li( "To find out more visit  ",
        tags$a("ruminate.ubiquity.tools", href=main_url),""),
tags$li( "To give it a try you can download a test dataset ",
        tags$a("here", href=data_url),""),
tags$li( "Go to  ",
        tags$a("useruminate.ubiquity.tools", href=use_url)," for a video
        demonstrating how to use ruminate"),
tags$li( "If you run into any problems, have questions, or want a feature please
        visit the ",
        tags$a("issues", href=issue_url)," page")
)


ui <- shinydashboard::dashboardPage(
  skin="black",
  shinydashboard::dashboardHeader(title="ruminate"),
  shinydashboard::dashboardSidebar(
     shinydashboard::sidebarMenu(
       shinydashboard::menuItem("Load/Save",
                                tabName="loadsave",
                                icon=icon("arrow-down-up-across-line")) ,
       shinydashboard::menuItem("Transform Data", tabName="wrangle", icon=icon("shuffle")),
       shinydashboard::menuItem("Visualize",      tabName="plot",    icon=icon("chart-line")),
       shinydashboard::menuItem("NCA",            tabName="nca",     icon=icon("chart-area")),
       shinydashboard::menuItem("App Info",       tabName="sysinfo", icon=icon("book-medical"))
     )
  ),
  shinydashboard::dashboardBody(
  tags$head(
    tags$style(HTML(CSS))
  ),
    shinydashboard::tabItems(
       shinydashboard::tabItem(tabName="nca",
               shinydashboard::box(title="Non-Compartmental Analysis", width=12,
               fluidRow( prompter::use_prompt(),
               column(width=12,
               htmlOutput(NS("NCA",  "NCA_ui_compact")))))
               ),
       shinydashboard::tabItem(tabName="loadsave",
         #     shinydashboard::box(title=NULL, width=12,
               shinydashboard::tabBox(
                 width = 12,
                 title = NULL,
                 shiny::tabPanel(id="load_data",
                          title=tagList(shiny::icon("file-arrow-up"),
                                        "Load Data"),
                   fluidRow(
                     column(width=6,
                       div(style="display:inline-block;width:100%",
                       htmlOutput(NS("UD", "ui_ud_load_data"))),
                       htmlOutput(NS("UD", "ui_ud_clean")),
                       htmlOutput(NS("UD", "ui_ud_select_sheets")),
                       htmlOutput(NS("UD", "ui_ud_workflows")),
                       htmlOutput(NS("UD", "ui_ud_text_load_result"))),
                     column(width=6,
                         tags$p(
                             tags$img(
                             class = "wrapfig",
                             src   = logo_url,
                             width = 150,
                             alt = "formods logo" ),
                         intro_text
                         ))
                   ),
                 fluidRow(
                   column(width=12,
                          div(style="display:inline-block;vertical-align:top",
                                    htmlOutput(NS("UD", "ui_ud_data_preview")))
                          ))
                 ),
                 shiny::tabPanel(id="save_state",
                          title=tagList(shiny::icon("arrow-down-up-across-line"),
                                        "Save or Load Analysis"),
                 fluidRow(
                   column(width=5,
                          div(style="display:inline-block;vertical-align:top",
                   htmlOutput(NS("ASM", "ui_asm_compact"))
                   ))
                   )
                 )
               )
         #     ),
               ),
       shinydashboard::tabItem(tabName="wrangle",
               shinydashboard::box(title="Transform and Create Views of Your Data", width=12,
               fluidRow(
               column(width=12,
               htmlOutput(NS("DW",  "DW_ui_compact")))))
               ),
       shinydashboard::tabItem(tabName="plot",
               shinydashboard::box(title="Visualize Data", width=12,
               htmlOutput(NS("FG",  "FG_ui_compact")))),
       shinydashboard::tabItem(tabName="sysinfo",
         #     box(title="System Details", width=12,
               shinydashboard::tabBox(
                 width = 12,
                 title = NULL,
                 shiny::tabPanel(id="sys_packages",
                          title=tagList(shiny::icon("box-open"),
                                        "Installed Packages"),
                 htmlOutput(NS("ASM", "ui_asm_sys_packages"))
                 ),
                 shiny::tabPanel(id="sys_modules",
                          title=tagList(shiny::icon("cubes"),
                                        "Loaded Modules"),
                 htmlOutput(NS("ASM", "ui_asm_sys_modules"))
                 ),
                 shiny::tabPanel(id="sys_log",
                          title=tagList(shiny::icon("clipboard-list"),
                                        "Log"),
                 verbatimTextOutput(NS("ASM", "ui_asm_sys_log"))
                 ),
                 shiny::tabPanel(id="sys_options",
                          title=tagList(shiny::icon("sliders"),
                                        "R Options"),
                 htmlOutput(NS("ASM", "ui_asm_sys_options"))
                 ),
                 shiny::tabPanel(id="sys_deps",
                          title=tagList(shiny::icon("box-open"),
                                        "Dependencies"),
                 htmlOutput("ui_sys_deps")
                 )
         #       )
               ))
      )
    )
  )

# Main app server
server <- function(input, output, session) {

  # Empty reactive object to track and react to
  # changes in the module state outside of the module
  react_FM = reactiveValues()

  # Module IDs and the order they are needed for code generation
  mod_ids = c("UD", "DW", "FG", "NCA", "MB")

  # If the ftmptest file is present we load test data
  if(file.exists(ftmptest)){
    sources = c(system.file(package="formods",  "preload", "ASM_preload.yaml"),
                system.file(package="formods",  "preload", "UD_preload.yaml"),
                system.file(package="formods",  "preload", "FG_preload.yaml"),
                system.file(package="formods",  "preload", "DW_preload.yaml"),
                system.file(package="ruminate", "preload", "NCA_preload.yaml"))

    res = FM_app_preload(session=session, sources=sources)
  # Otherwise we look for a preload file and load that if it exists
  } else if(file.exists("preload.yaml")){
    shinybusy::show_modal_spinner(text="Preloading analysis, be patient", session=session)
    res = FM_app_preload(session=session, sources="preload.yaml")
    shinybusy::remove_modal_spinner(session = session)
  }

  # Module servers
  formods::ASM_Server( id="ASM",
                       deployed      = deployed,
                       react_state   = react_FM,
                       FM_yaml_file  = formods.yaml,
                       MOD_yaml_file = ASM.yaml,
                       mod_ids       = mod_ids)
  formods::UD_Server(  id ="UD", id_ASM = "ASM",
                       deployed         = deployed,
                       react_state      = react_FM,
                       MOD_yaml_file    = UD.yaml,
                       FM_yaml_file     = formods.yaml)
  formods::DW_Server(  id="DW",       id_ASM = "ASM",
                       id_UD = "UD",
                       deployed         = deployed,
                       react_state      = react_FM,
                       MOD_yaml_file    = DW.yaml,
                       FM_yaml_file     = formods.yaml)
  formods::FG_Server(  id="FG",     id_ASM = "ASM",
                       id_UD = "UD", id_DW = "DW",
                       deployed         = deployed,
                       react_state      = react_FM,
                       MOD_yaml_file    = FG.yaml,
                       FM_yaml_file     = formods.yaml)
  ruminate::NCA_Server(id    ="NCA", id_ASM = "ASM",
                       id_UD = "UD", id_DW  = "DW",
                       deployed         = deployed,
                       react_state      = react_FM,
                       MOD_yaml_file    = NCA.yaml,
                       FM_yaml_file     = formods.yaml)

  output$ui_sys_deps = renderUI({
    pcf = formods_check(verbose = FALSE)
    pcr = ruminate_check(verbose = FALSE)

    dep_sum = NULL
    if(!is.null(pcf[["found_pkgs"]])){
      dep_sum = rbind(dep_sum, 
        data.frame(
          Package      = "formods",
          Dependency   = pcf[["found_pkgs"]],
          Status       = "found"
        ))
    }
    if(!is.null(pcf[["missing_pkgs"]])){
      dep_sum = rbind(dep_sum, 
        data.frame(
          Package      = "formods",
          Dependency   = pcf[["missing_pkgs"]],
          Status       = "missing"
        ))
    }
    if(!is.null(pcr[["found_pkgs"]])){
      dep_sum = rbind(dep_sum, 
        data.frame(
          Package      = "ruminate",
          Dependency   = pcr[["found_pkgs"]],
          Status       = "found"
        ))
    }
    if(!is.null(pcr[["missing_pkgs"]])){
      dep_sum = rbind(dep_sum, 
        data.frame(
          Package      = "ruminate",
          Dependency   = pcr[["missing_pkgs"]],
          Status       = "missing"
        ))
    }

    uiele = DT::datatable(dep_sum)

  uiele})

}

shinyApp(ui, server)
}