diff --git a/thinkCausal/DESCRIPTION b/thinkCausal/DESCRIPTION index 4c74f49..feba1cd 100644 --- a/thinkCausal/DESCRIPTION +++ b/thinkCausal/DESCRIPTION @@ -53,7 +53,7 @@ Config/testthat/edition: 3 Encoding: UTF-8 Language: en-US LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 VignetteBuilder: knitr BugReports: https://priism-center.github.io/thinkCausal//issues Remotes: diff --git a/thinkCausal/R/app_ui.R b/thinkCausal/R/app_ui.R index f1697f9..ec282c4 100644 --- a/thinkCausal/R/app_ui.R +++ b/thinkCausal/R/app_ui.R @@ -29,6 +29,7 @@ app_ui <- function(request) { # add beta ribbon add_beta_ribbon(), + create_return_btn(), # message when server disconnects # TODO: this can be removed for native installation diff --git a/thinkCausal/R/fct_ui.R b/thinkCausal/R/fct_ui.R index e94d67a..4f8dcae 100644 --- a/thinkCausal/R/fct_ui.R +++ b/thinkCausal/R/fct_ui.R @@ -56,3 +56,36 @@ add_beta_ribbon <- function(){ ) ) } + + +#' Button to be used within Analysis flow to link to Learning articles +#' +#' @param tabName The tab name of the Learning article to link to +#' @param tabNameCurrent The tab name of the point in the Analysis flow this function is called. +#' @param label Button label +#' +#' @return html +#' @author Joe Marlo +#' @noRd +#' +#' @examples +#' create_go_to_learning_btn('learn_1', 'analysis_1', 'Article 1') +create_go_to_learning_btn <- function(tabName, tabNameCurrent, label){ + htmltools::tags$button( + type = 'button', + class = "btn btn-primary", + onclick = glue::glue("show_back_button(); log_page('{tabNameCurrent}'); go_to_shiny_page('{tabName}', false);"), + glue::glue("Learn more at {label}") + ) +} +#' @describeIn create_go_to_learning_btn Hovering button that returns user back to the latest Analysis page +create_return_btn <- function(){ + htmltools::tags$button( + id = 'back_to_analysis', + type = 'button', + class = "btn btn-primary nav-path", + style = "position: fixed; bottom: 30px; right: 20px; z-index: 100; display: none; max-width: 200px;", + onclick = "go_to_shiny_page(last_page, false); hide_back_button();", + glue::glue("Back to Analysis") + ) +} diff --git a/thinkCausal/R/mod_analysis_upload.R b/thinkCausal/R/mod_analysis_upload.R index e394159..6d90b64 100644 --- a/thinkCausal/R/mod_analysis_upload.R +++ b/thinkCausal/R/mod_analysis_upload.R @@ -62,7 +62,8 @@ mod_analysis_upload_ui <- function(id) { inputId = ns('analysis_upload_data_button_columnAssignSave'), class = 'nav-path', label = 'Next' - ) + ), + create_go_to_learning_btn('learn', 'analysis_upload', 'Learning') ) ), column(width = 9, diff --git a/thinkCausal/inst/app/www/js/ui.js b/thinkCausal/inst/app/www/js/ui.js index 6e72368..c7c804f 100644 --- a/thinkCausal/inst/app/www/js/ui.js +++ b/thinkCausal/inst/app/www/js/ui.js @@ -25,7 +25,22 @@ $( window ).on( "load", function() { function go_to_shiny_page(page, toggleHelp) { document.body.scrollTop = document.documentElement.scrollTop = 0; setTimeout(function(){Shiny.setInputValue("js_open_page", {page: page, toggleHelp: toggleHelp}, {priority: "event"}); }, 400); -} +}; + +// log previous page for return to analysis button +let last_page = ""; + +function log_page(page){ + last_page = page +}; + +function show_back_button() { + $("#back_to_analysis").show() +}; + +function hide_back_button() { + $("#back_to_analysis").hide() +}; // popup to prevent user from accidentally leaving the page if closing the tab or using the browser back button window.onbeforeunload = function() { return "Please use the navigation buttons on the page."; };