R/app_ui.R

Defines functions golem_add_external_resources create_body create_sidebar create_navbar app_ui

Documented in create_body create_navbar create_sidebar

#' The application User-Interface
#'
#' @param request Internal parameter for `{shiny}`.
#'     DO NOT REMOVE.
#' @import shiny
#' @noRd
app_ui <- function(request) {
  tagList(
    # Leave this function for adding external resources
    golem_add_external_resources(),
    hamiltonThemes::use_bs4Dash_distill_css(),
    # List the first level UI elements here
    bs4Dash::bs4DashPage(
      navbar = create_navbar(),
      sidebar = create_sidebar(),
      body = create_body()
    )
  )
}

#' Creates app's navbar
create_navbar <- function() {
  bs4Dash::bs4DashNavbar(
    skin = "light",
    status = "light",
    border = TRUE,
    sidebarIcon = "bars",
    compact = FALSE,
    controlbarIcon = "th"
  )
}

#' Creates app's sidebar
create_sidebar <- function() {
  customBs4DashSidebar(
    skin = "light",
    status = "primary",
    title = "Hamilton Institute",
    brandColor = "dark",
    url = "https://www.maynoothuniversity.ie/hamilton",
    src = "www/maynooth_university_logo.png",
    elevation = 1,
    opacity = 0.8,
    # bs4SidebarUserPanel(
    #   img = "https://image.flaticon.com/icons/svg/1149/1149168.svg",
    #   text = "Welcome Onboard!"
    # ),
    bs4Dash::bs4SidebarMenu(
      bs4Dash::bs4SidebarMenuItem(
        "Summary",
        tabName = "summary",
        icon = "dashboard"
      ),
      bs4Dash::bs4SidebarMenuItem(
        "Ireland map",
        tabName = "map",
        icon = "map"
      ),
      bs4Dash::bs4SidebarMenuItem(
        "Graphs",
        tabName = "graphs",
        icon = "bar-chart-o"
      ),
      bs4Dash::bs4SidebarMenuItem(
        "Animations",
        tabName = "animations",
        icon = "chart-line"
      ),
      # bs4Dash::bs4SidebarMenuItem(
      #   "Interventions",
      #   tabName = "interventions",
      #   icon = "user-plus"
      # ),
      bs4Dash::bs4SidebarMenuItem(
        "Sources",
        tabName = "sources",
        icon = "list-alt"
      )
    )
  )
}

#' Creates app's body
create_body <- function() {
  bs4Dash::bs4DashBody(
    hamiltonThemes::use_bs4Dash_distill_theme(),
    bs4Dash::bs4TabItems(
      bs4Dash::bs4TabItem(
        tabName = "summary",
        mod_summary_ireland_ui("summary_ireland_ui_1"),
        br(),
        mod_summary_global_ui("summary_global_ui_1")
      ),
      bs4Dash::bs4TabItem(
        tabName = "map",
        mod_map_ui("map_ui_1")
      ),
      bs4Dash::bs4TabItem(
        tabName = "graphs",
        mod_graphs_ui("graphs_ui_1")
      ),
      bs4Dash::bs4TabItem(
        tabName = "animations",
        mod_animations_ui("animations_ui_1")
      ),
      bs4Dash::bs4TabItem(
        tabName = "interventions",
        mod_interventions_ui("interventions_ui_1")
      ),
      bs4Dash::bs4TabItem(
        tabName = "sources",
        mod_sources_ui("sources_ui_1")
      )
    )
  )
}

#' 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')
  )

  tags$head(
    favicon(ext = "png"),
    bundle_resources(
      path = app_sys('app/www'),
      app_title = 'hamiltonCovid19'
    )
  )
}
curso-r/hamiltonCovid19 documentation built on Aug. 6, 2021, 10:43 p.m.