Skip to content

Commit

Permalink
Added Word placeholders to ASM_preload().
Browse files Browse the repository at this point in the history
Created vignette to describe how to load data into the app.

Created is_shiny() function.
  • Loading branch information
john-harrold committed Nov 28, 2024
1 parent c75677b commit f9a0603
Show file tree
Hide file tree
Showing 129 changed files with 1,554 additions and 418 deletions.
10 changes: 7 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# formods 0.2.0 (development version)

* Created preload functionality to allow modules to save to and be loaded from yaml files
* Created preload functionality to allow modules to save to and be loaded from yaml files.
* Updated the `ZZ_Server.R` to include save/load of preload yaml files.
* Updated the save/load functionality for the ASM module to switch to use this functionality (this breaks the previous save methodology.)
* Creating workflows to automate analysis initialization
* Creating workflows to automate analysis initialization .
* Updated FM_compact.R test app to use the preload script in an unzipped saved
analysis.
* Created `is_shiny()` function.


# formods 0.1.7

* Added word placeholders to the UI so the user can change them when generating reports/saving the app state.
* Fixed issue with `has_updated()` where zero values from ui inputs were not taking effect because of a special case with buttons. This requires an `is_button=TRUE` argument for buttons.
* Updated the `ZZ_Server.R` template to use `has_updated()`
* Updated the `ZZ_Server.R` template to use `has_updated()`.

# formods 0.1.6

Expand Down
44 changes: 42 additions & 2 deletions R/ASM_Server.R
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,18 @@ ASM_Server <- function(id,
if(state[["ASM"]][["isgood"]]){
if( length(state[["ASM"]][["ph_uis"]]) > 0){
for(ph_ui in names(state[["ASM"]][["ph_uis"]])){
tmp_value = state[["ASM"]][["ui"]][[ph_ui]]
if(tmp_value == ""){
tmp_value = state[["ASM"]][["ph_uis"]][[ph_ui]][["value"]]
}

tmp_uiele =
textInput(
inputId = NS(id, ph_ui),
width = state[["yaml"]][["FM"]][["reporting"]][["phs_formatting"]][["width"]],
label = NULL,
placeholder = state[["ASM"]][["ph_uis"]][[ph_ui]][["name"]],
value = state[["ASM"]][["ui"]][[ph_ui]])
value = tmp_value)

if(is.character( state[["ASM"]][["ph_uis"]][[ph_ui]][["tooltip"]])){
tmp_uiele = FM_add_ui_tooltip(
Expand Down Expand Up @@ -1006,11 +1011,40 @@ ASM_preload = function(session, src_list, yaml_res=NULL, mod_ID=NULL, react_sta
FM_yaml_file = FM_yaml_file,
MOD_yaml_file = MOD_yaml_file)


# Populating any word document preload values:
if(length(names(src_list[[mod_ID]][["docx_ph"]])) > 0){
# Placeholders defined for the app in the formods.yaml file
fm_phs = yaml_res[[mod_ID]][["fm_cfg"]][["FM"]][["reporting"]][["phs"]]

# Just the names found
found_ph_names = as.vector(unlist(fm_phs)[names(unlist(fm_phs)) == "name"])

# placeholders loaded from the preload file
l_phs = src_list[[mod_ID]][["docx_ph"]]

# Setting word placeholders
FM_le(state, paste0("setting word placeholders: "))
for(ph_ui in names(state[["ASM"]][["ph_uis"]])){
# If the placeholder was found in the preload AND
# if the name exists in formods.yaml then we set it
ph_name = state[["ASM"]][["ph_uis"]][[ ph_ui ]][["name"]]
if(ph_name %in% names(l_phs) & ph_name %in% found_ph_names){
formods::FM_le(state,paste0(" -> setting docx ph: ",ph_name, " = ", l_phs[[ph_name]]))
# Updates at the ui storage location
state[["ASM"]][["ui"]][[ph_ui]] = l_phs[[ph_name]]

# Updates the default value as well
state[["ASM"]][["ph_uis"]][[ph_ui]][["value"]] = l_phs[[ph_name]]
}
}
}

# Required for proper reaction:
react_state[[mod_ID]] = list(ASM = list(checksum=state[["ASM"]][["checksum"]]))

# Saving the state
if(any(c("session_proxy", "ShinySession") %in% class(session))){
if(is_shiny(session)){
FM_set_mod_state(session, mod_ID, state)
} else {
session = FM_set_mod_state(session, mod_ID, state)
Expand Down Expand Up @@ -1118,6 +1152,12 @@ ASM_mk_preload = function(state){
mod_yaml = file.path("config", basename(state[["MOD_yaml_file"]]))
)

# Setting the word placeholder values
for(ph_ui in names(state[["ASM"]][["ph_uis"]])){
ph_name = state[["ASM"]][["ph_uis"]][[ ph_ui ]][["name"]]
yaml_list[[ state[["id"]] ]][["docx_ph"]][[ph_name]] = state[["ASM"]][["ui"]][[ph_ui]]
}

formods::FM_le(state,paste0("mk_preload isgood: ",isgood))

res = list(
Expand Down
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ navbar:
href: articles/included_modules.html
- text: "Making Modules"
href: articles/making_modules.html
- text: "Automating Workflows and Preloading Content"
href: articles/preload.html
- text: "Functions"
icon: fas fa-hat-wizard
href: reference/index.html
Expand Down
1 change: 1 addition & 0 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f9a0603

Please sign in to comment.