R/app_ui.R

Defines functions golem_add_external_resources app_ui

#' The application User-Interface
#'
#' @param request Internal parameter for `{shiny}`.
#'     DO NOT REMOVE.
#' @import shiny
#' @import dplyr
#'
#' @noRd

app_ui <- function(request) {
  tagList(
    # Leave this function for adding external resources
    golem_add_external_resources(),
    # Your application UI logic
    fluidPage(
      theme = theme,
      navbarPage(
        title = span(
          img(src = "www/rmd/img/favicon.png", height = "80px"),
          "Washington Climate Smart Estimator"
        ),
        collapsible = TRUE,
        tabPanel(
          title = "Explore the data",
          mod_explore_ui("explore_tab")
        ),
        tabPanel(
          title = "Calculate your estimate",
          mod_estimate_ui("estimate_tab")
        ),
        tabPanel(
          title = "Understand your impact",
          mod_impact_ui("impact_tab")
        ),
        tabPanel(
          title = "About",
          column(10,
            offset = 1,
            shinydashboard::box(
              width = NULL, status = "primary",
              includeMarkdown(normalizePath("inst/app/www/rmd/about.md"))
            )
          )
        )
      )
    )
  )
}

#' Add external Resources to the Application
#'
#' This function is internally used to add external
#' resources inside the Shiny application.
#'
#' @import shiny
#' @importFrom golem add_resource_path activate_js favicon bundle_resources
#' @noRd

golem_add_external_resources <- function() {
  add_resource_path(
    "www",
    app_sys("app/www")
  )

  source("R/globals.R")

  # Register Source Sans Pro font
  if (!ggiraph::font_family_exists("Source Sans Pro")) {
    systemfonts::register_font(
      name = "Source Sans Pro",
      plain = list("inst/app/www/fonts/source-sans-pro-v21-latin-regular.woff", 0),
      bold = list("inst/app/www/fonts/source-sans-pro-v21-latin-700.woff", 0),
      italic = list("inst/app/www/fonts/source-sans-pro-v21-latin-italic.woff", 0),
      bolditalic = list("inst/app/www/fonts/source-sans-pro-v21-latin-700italic.woff", 0)
    )
  }

  tags$head(
    favicon(),
    favicon(ext = "png"),
    bundle_resources(
      path = app_sys("app/www"),
      app_title = "WaCSE"
    ),
    tags$link(
      rel = "stylesheet",
      type = "text/css",
      href = "www/css/style.css"
    ),
    shinyjs::useShinyjs(),
    shinyFeedback::useShinyFeedback(),
    shinyWidgets::useShinydashboard(),
    shinyWidgets::setBackgroundColor(color = "#faf9f0"),
    waiter::useWaiter(),
    waiter::waiterPreloader(html = waiter::spin_hexdots(), fadeout = TRUE),
    shinydisconnect::disconnectMessage(
      text = "Your session timed out. Please refresh the page and try again.",
      refresh = "Refresh",
      background = "#FFFFFF",
      colour = "#444444",
      refreshColour = "#337AB7",
      overlayColour = "#000000",
      overlayOpacity = 0.6,
      width = 450,
      top = "center",
      size = 22,
      css = ""
    ),
    includeHTML("inst/app/www/google-analytics.html"),
    # warn user that changes are not saved when closing the window.
    # unfortunately, custom messages are no longer supported by modern browsers.
    # tags$script(HTML("
    #             // Enable navigation prompt
    #             window.onbeforeunload = function() {
    #               return 'Did you download your data and reports?';
    #             };
    #             "))
    # Add here other external resources
    # for example, you can add shinyalert::useShinyalert()
  )
}
# spinner options
options(spinner.type = 7, spinner.color = "#81B29A", spinner.size = 1.5)
WA-Department-of-Agriculture/WaCSEshiny documentation built on June 2, 2025, 12:35 p.m.