Skip to content

Commit

Permalink
Added copy to clipboard functionality to the ZZ_Server.R template
Browse files Browse the repository at this point in the history
  • Loading branch information
john-harrold committed Jan 5, 2024
1 parent 8c3b6c8 commit 690ed11
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
12 changes: 0 additions & 12 deletions R/formods.R
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,6 @@ FM_fetch_app_code = function(session, state, mod_ids){
if(!is.null(MOD_TYPE)){
if(MOD_TYPE == gen_mod){

## Getting the preamble code. This just collects it in
## preamble_chunks and will be appended to the top down below.
#mod_deps = FM_fetch_deps(state=tmp_state, session = session)
#if("package_code" %in% names(mod_deps)){
# preamble_chunks = c(preamble_chunks, mod_deps$package_code)
#}

MOD_FUNC = paste0(MOD_TYPE, "_fetch_code")
# We make sure the code generation function exists
# and if it does we generate the code for that module
Expand Down Expand Up @@ -1221,11 +1214,6 @@ FM_init_state = function(
# This holds all the ui IDs from the interface
state[[MT]][["ui_ids"]] = ui_ids

## This tracks if the ui_id has been initialized or not:
#for(tmp_ui_id in ui_ids){
# state[[MT]][["ui_ids_init"]][[tmp_ui_id]] = FALSE
#}

# Messaging passed back to the user
state[[MT]][["ui_msg"]] = NULL

Expand Down
34 changes: 29 additions & 5 deletions inst/templates/ZZ_Server.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,29 @@
session = session)
})
#------------------------------------
# Copying element code to the clipboard
observeEvent(input$button_clk_clip, {
state = ===ZZ===_fetch_state(id = id,
id_ASM = id_ASM,
input = input,
session = session,
FM_yaml_file = FM_yaml_file,
MOD_yaml_file = MOD_yaml_file,
react_state = react_state)

# This is all conditional on the whether clipr is installed $
# and if the app isn't deployed
if((system.file(package="clipr") != "") &
!deployed){

# Pulling out the current element
current_ele = ===ZZ===_fetch_current_element(state)
uiele = current_ele[["code"]]

clipr::write_clip(uiele)
}
})
#------------------------------------
# Removing holds
remove_hold_listen <- reactive({
list(
Expand Down Expand Up @@ -716,7 +739,7 @@
# the current element
ui_ele = c("element_name")

# This contains all of the relevant ui_ids in the module. You need to append
# This contains all of the relevant ui_ids in the module. You need to append
# ui_ids that are outside of the current element here as well.
ui_ids = c(button_counters,
ui_ele,
Expand Down Expand Up @@ -779,7 +802,7 @@ code}
#'@description Appends report elements to a formods report.
#'@param state ===ZZ=== state from \code{===ZZ===_fetch_state()}
#'@param rpt Report with the current content of the report which will be appended to in
#'this function. For details on the structure see the documentation for
#'this function. For details on the structure see the documentation for
#' \code{\link[onbrand]{template_details}}
#'@param rpttype Type of report to generate (supported "xlsx", "pptx", "docx").
#'@param gen_code_only Boolean value indicating that only code should be
Expand Down Expand Up @@ -897,7 +920,7 @@ res}
#' \item{MOD_TYPE:} Type of module.
#' \item{id:} Module ID.
#' \item{rx_obj:} The rxode2 object name that holds the model.
#' \item{fcn_def:} Text to define the model
#' \item{fcn_def:} Text to define the model.
#' \item{MDLMETA:} Notes about the model.
#' \item{code:} Code to generate the model.
#' \item{checksum:} Module checksum.
Expand Down Expand Up @@ -1002,8 +1025,8 @@ res}
new_chk = digest::digest(chk_str, algo=c("md5"))

if(has_updated(old_chk, new_chk)){
state[["===ZZ==="]][["checksum"]] = new_chk
FM_le(state, paste0("module checksum updated:", state[["===ZZ==="]][["checksum"]]))
state[["===ZZ==="]][["checksum"]] = new_chk
FM_le(state, paste0("module checksum updated: ", state[["===ZZ==="]][["checksum"]]))
}

state}
Expand Down Expand Up @@ -1247,6 +1270,7 @@ current_element}
# updating the checksum for the current element
tmp_ele = element
tmp_ele[["checksum"]] = ""

tmp_checksum = digest::digest(tmp_ele, algo=c("md5"))
if(has_updated(element[["checksum"]], tmp_checksum)){
FM_le(state, paste0("===ELEMENT=== checksum updated: ", tmp_checksum))
Expand Down
2 changes: 2 additions & 0 deletions inst/templates/ZZ_module_components.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#library(formods)
library(shinydashboard)
library(prompter)
library(clipr)

#https://fontawesome.com/icons?from=io

Expand Down
3 changes: 2 additions & 1 deletion vignettes/making_modules.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ The module template will create a standard set of functions for you. The `MM` be
- `label` Text label for the model.
- `MOD_TYPE` Short name for the type of module.
- `id` module ID.
- `rx_obj` The rxode2 object name that holds the model.
- `rx_obj` The rxode2 object that holds the model.
- `rx_obj_name` The rxode2 object name in generated code.
- `fcn_def` Text to define the model
- `DSMETA` Verbose metadata describing model.
- `code` Complete code to build the model.
Expand Down

0 comments on commit 690ed11

Please sign in to comment.