Skip to content

Commit

Permalink
Changing logic to use has_updated instead of has_changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-harrold committed Dec 16, 2023
1 parent 6f9c31e commit 2292c07
Show file tree
Hide file tree
Showing 104 changed files with 632 additions and 396 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: formods
Type: Package
Title: 'Shiny' Modules for General Tasks
Version: 0.1.3
Version: 0.1.4
Authors@R: c(person("John", "Harrold",
role = c("aut", "cre"),
email = "[email protected]",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export(fers_builder)
export(fetch_hold)
export(fetch_package_version)
export(has_changed)
export(has_updated)
export(icon_link)
export(is_installed)
export(new_module_template)
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# formods 0.1.3
# formods 0.1.3 (development version)

* Fixed bug preventing the same file name from being uploaded.
* Fixed bug where user files were stored in the same location for different sessions

# formods 0.1.2

* development version
* Added `new_module_template()` to create new module templates and `use_formods()`
to automatically add the files to a package.
* Updated app info in ASM to split up the uiele into diferent components.
Expand Down
65 changes: 62 additions & 3 deletions R/formods.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,48 @@ has_changed = function(ui_val = NULL,
}
res}

#'@export
#'@title Detect if a UI element has updated
#'@description Takes a UI element value and an older value and determines if
#'it has been modified
#'@param ui_val Current value from the UI.
#'@param old_val Last value of of the element.
#'defined.
#'@return Boolean result of the comparison
#'@examples
#' changed_true = has_updated(ui_val = "a", old_val = "")
#' changed_true
#' changed_false = has_updated(ui_val = "a", old_val = "a")
#' changed_false
has_updated = function(ui_val = NULL,
old_val = NULL){
res = FALSE

# Detecting length differences
if(length(ui_val) != length(old_val)){
res = TRUE
} else if((length(ui_val) == length(old_val)) &
length(ui_val) > 1){
# here we're comparing vectors
if(!all(ui_val %in% old_val)){
res = TRUE
}
} else {
# here we're comparing scalers
if((length(ui_val) == 1) &
(length(old_val) == 1)){
if(ui_val != old_val){
res = TRUE
#message(paste0("old_val: ", old_val))
#message(paste0("ui_val: ", ui_val))
}
} else {
message("Unknown scenario has_updated:")
message(paste0("old_val: ", old_val))
message(paste0("ui_val: ", ui_val ))
}
}
res}
#'@export
#'@title Removes Hold on UI Element
#'@description When some buttons are clicked they will change the state of the
Expand Down Expand Up @@ -662,7 +704,7 @@ isgood}
#' mr = FM_message("This is a success message", entry_type="success")
#' mr = FM_message("This is a warning message", entry_type="warning")
FM_message = function(line, escape_braces=TRUE, entry_type="alert"){
if(system.file(package="cli") != ""){
if(is_installed("cli") != ""){
if(escape_braces){
if(entry_type=="alert"){
cli::cli_alert("{line}") }
Expand All @@ -674,6 +716,12 @@ FM_message = function(line, escape_braces=TRUE, entry_type="alert"){
cli::cli_alert_info("{line}") }
if(entry_type=="success"){
cli::cli_alert_success("{line}") }
if(entry_type=="h1"){
cli::cli_h1("{line}") }
if(entry_type=="h2"){
cli::cli_h2("{line}") }
if(entry_type=="h3"){
cli::cli_h3("{line}") }
} else {
if(entry_type=="alert"){
cli::cli_alert(line)}
Expand All @@ -685,6 +733,12 @@ FM_message = function(line, escape_braces=TRUE, entry_type="alert"){
cli::cli_alert_info(line)}
if(entry_type=="success"){
cli::cli_alert_success(line)}
if(entry_type=="h1"){
cli::cli_h1(line)}
if(entry_type=="h2"){
cli::cli_h2(line)}
if(entry_type=="h3"){
cli::cli_h3(line)}
}
} else {
message(line)
Expand Down Expand Up @@ -1171,6 +1225,11 @@ 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 All @@ -1182,7 +1241,7 @@ FM_init_state = function(
state[["FM_yaml_file"]] = FM_yaml_file
state[["MOD_yaml_file"]] = MOD_yaml_file

# If we're not in a shiny environment then
# If we're not in a shiny environment then
# the token will ne NULL otherwise it will
# be a checksum
if(is.null(session$token)){
Expand Down Expand Up @@ -2209,7 +2268,7 @@ res}
is_installed = function(pkgname){

res = TRUE
if(system.file(package = pkgname) == ""){
if(!requireNamespace(pkgname, quietly=TRUE)){
res = FALSE
}

Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ reference:
- fetch_hold
- fetch_package_version
- has_changed
- has_updated
- icon_link
- is_installed
- new_module_template
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion 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 2292c07

Please sign in to comment.