Skip to content

Commit

Permalink
added functionality to link to learning article from analysis flow wi…
Browse files Browse the repository at this point in the history
…th back button
  • Loading branch information
joemarlo committed Feb 6, 2024
1 parent c258f63 commit f6d45dc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion thinkCausal/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions thinkCausal/R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions thinkCausal/R/fct_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
}
3 changes: 2 additions & 1 deletion thinkCausal/R/mod_analysis_upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion thinkCausal/inst/app/www/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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."; };

0 comments on commit f6d45dc

Please sign in to comment.