R/utils_help_popups.R

Defines functions help_popups

Documented in help_popups

#' Help Popups
#'
#' Adds help files to a page
#'
#' @param page the page to load help file for, stored in inst/app/data/\{\{page\}\}_help.json
#'
#' @import shiny
#' @importFrom purrr imap map
#' @importFrom jsonlite read_json
#' @importFrom shinyWidgets ask_confirmation
help_popups <- function(page) {
  file <- paste0("app/data/", page, "_help.json") %>%
    app_sys()

  if (!file.exists(file)) {
    stop(paste("no help file for", page, "exists"))
  }

  file %>%
    read_json(TRUE) %>%
    imap(function(data, input_name) {
      # extract the text field. each line of text is converted to a paragraph. if that paragraph starts with a ":",
      # then we put the text before the ":" in bold text, followed by the rest of the text.
      text <- data$text %>%
        strsplit(": ") %>%
        map(~if (length(.x) >= 2) {
          tags$p(tags$strong(.x[[1]]), paste(.x[-1], collapse = " "))
        } else {
          tags$p(.x)
        })

      function() ask_confirmation(
        paste0(input_name, "_box"),
        data$title,
        tagList(text),
        "question",
        "ok",
        closeOnClickOutside = TRUE,
        showCloseButton = FALSE,
        html = TRUE
      )
    })
}
The-Strategy-Unit/723_mh_covid_surge_modelling documentation built on April 13, 2022, 8:52 a.m.