Skip to contents

Merges default app options with the changes made in the UI

Usage

MB_fetch_state(
  id,
  id_ASM,
  input,
  session,
  FM_yaml_file,
  MOD_yaml_file,
  react_state
)

Arguments

id

Shiny module ID

id_ASM

ID string for the app state management module used to save and load app states

input

Shiny input variable

session

Shiny session variable

FM_yaml_file

App configuration file with FM as main section.

MOD_yaml_file

Module configuration file with MC as main section.

react_state

Variable passed to server to allow reaction outside of module (NULL)

Value

list containing the current state of the app including default values from the yaml file as well as any changes made by the user. The list has the following structure:

  • yaml: Full contents of the supplied yaml file.

  • MC: Module components of the yaml file.

  • MB:

    • isgood: Boolean object indicating if the file was successfully loaded.

    • checksum: This is an MD5 sum of the contents element and can be used to detect changes in the state.

  • MOD_TYPE: Character data containing the type of module "MB"

  • id: Character data containing the module id module in the session variable.

  • FM_yaml_file: App configuration file with FM as main section.

  • MOD_yaml_file: Module configuration file with MC as main section.

Examples

# Within shiny both session and input variables will exist,
# this creates examples here for testing purposes:
sess_res = MB_test_mksession()
#> → ASM: including file
#> → ASM:   source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → ASM:   dest:   file.path("config","report.docx")
#> → ASM: including file
#> → ASM:   source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → ASM:   dest:   file.path("config","report.pptx")
#> → ASM: including file
#> → ASM:   source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → ASM:   dest:   file.path("config","report.yaml")
#> → ASM: State initialized
#> → ASM: module isgood: TRUE
#> → MB: including file
#> → MB:   source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → MB:   dest:   file.path("config","report.docx")
#> → MB: including file
#> → MB:   source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → MB:   dest:   file.path("config","report.pptx")
#> → MB: including file
#> → MB:   source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → MB:   dest:   file.path("config","report.yaml")
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.R not found (skipping)
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.ctl not found (skipping)
#> → MB: module checksum updated:24933f86b657b9503f22440e8c4d3cac
#> → MB: State initialized
#> → MB: loading model idx: 1
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#> → MB: model checksum updated: 03794438dbfd3a3a27eebc39ad436203
#> → MB: module checksum updated:34a469deda5568fc0e260a6afd1891f3
#> → MB: setting name: One compartment model
#> → MB: setting time scale: hours
#> → MB: setting base from: user
#> → MB: setting catalog selection: 
#> → MB: setting base model id: manual
#> → MB: setting base model name: manual
#> → MB: model checksum updated: cc835f1a733e62e5519b3a962ae0ae89
#> → MB: module checksum updated:927a0ae0a0cdc1138d0d7d9fa0c05836
#> → MB: added element idx: 1
#> → MB: loading model idx: 2
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#> → MB: model checksum updated: fc406d7985a63a9d9180ee8cf5078467
#> → MB: module checksum updated:0022b3bca2d4246a8138498d608566b0
#> → MB: setting name: PK Biomarker
#> → MB: setting time scale: days
#> → MB: setting base from: user
#> → MB: setting catalog selection: 
#> → MB: setting base model id: manual
#> → MB: setting base model name: manual
#> → MB: model checksum updated: 24cee75002f07a3b3385b9a9a478760c
#> → MB: module checksum updated:b0996670161add364a6078a8c7872849
#> → MB: added element idx: 2
#> Called from: MB_preload(session = session, src_list = src_list, yaml_res = yaml_res, 
#>     mod_ID = mod_ID, react_state = react_state, quickload = quickload)
#> debug: formods::FM_le(state, paste0("module isgood: ", isgood))
#> → MB: module isgood: TRUE
#> debug: if (("ShinySession" %in% class(session))) {
#>     FM_set_mod_state(session, mod_ID, state)
#> } else {
#>     session = FM_set_mod_state(session, mod_ID, state)
#> }
#> debug: session = FM_set_mod_state(session, mod_ID, state)
#> debug: res = list(isgood = isgood, msgs = msgs, session = session, input = input, 
#>     react_state = react_state, state = state)
#> debug: res
session = sess_res$session
input   = sess_res$input

# Configuration files
FM_yaml_file  = system.file(package = "formods", "templates", "formods.yaml")
MOD_yaml_file = system.file(package = "ruminate", "templates", "MB.yaml")

# Creating an empty state object
state = MB_fetch_state(id              = "MB",
                       id_ASM          = "ASM",
                       input           = input,
                       session         = session,
                       FM_yaml_file    = FM_yaml_file,
                       MOD_yaml_file   = MOD_yaml_file,
                       react_state     = NULL)