diff --git a/NAMESPACE b/NAMESPACE index de7bd9f..697f103 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,9 +6,15 @@ export(footer_logo_section) export(footer_top_section) export(mod_footer_server) export(mod_footer_ui) +export(mod_sidebar_server) +export(mod_sidebar_ui) export(validate_image) +importFrom(bsicons,bs_icon) +importFrom(bslib,accordion) +importFrom(bslib,accordion_panel) importFrom(bslib,card_footer) importFrom(bslib,layout_columns) +importFrom(bslib,sidebar) importFrom(fontawesome,fa) importFrom(htmltools,HTML) importFrom(htmltools,tags) @@ -18,3 +24,6 @@ importFrom(shiny,NS) importFrom(shiny,icon) importFrom(shiny,includeCSS) importFrom(shiny,moduleServer) +importFrom(shiny,reactive) +importFrom(shiny,req) +importFrom(shinyWidgets,pickerInput) diff --git a/R/app_ui.R b/R/app_ui.R new file mode 100644 index 0000000..10ccf75 --- /dev/null +++ b/R/app_ui.R @@ -0,0 +1,110 @@ + +# ------------------------------------------------------------------------ +# +# Title : Shiny App UI +# By : Jimmy Briggs +# Date : 2024-11-08 +# +# ------------------------------------------------------------------------ + + +# internal ---------------------------------------------------------------- + +add_external_resources <- function() { + shiny::addResourcePath( + "www", + system.file("www", package = "gmhdatahub") + ) + + htmltools::tags$head( + htmltools::tags$link( + rel = "shortcut icon", + type = "image/x-icon", + href = "www/favicon.ico" + ), + golem::bundle_resources( + path = system.file("www", package = "gmhdatahub"), + app_title = "gmhdatahub" + ), + shinyjs::useShinyjs(), + waiter::use_waiter() + ) +} + +# UI ---------------------------------------------------------------------- + +app_ui <- function(req) { + + force(req) + + htmltools::tagList( + add_external_resources(), + bslib::page_navbar( + id = "nav", + lang = "en", + window_title = "GMH DataHub", + theme = bslib::bs_theme(version = 5), + title = mod_title_ui("app"), + footer = mod_footer_ui("app"), + sidebar = mod_sidebar_ui("app"), + bslib::nav_panel( + title = "Home", + value = "home", + icon = shiny::icon("home")#, + # mod_home_ui("app") + ), + bslib::nav_panel( + title = "Data", + value = "data", + icon = shiny::icon("database")#, + # mod_data_ui("app") + ), + bslib::nav_panel( + title = "Analysis", + value = "analysis", + icon = shiny::icon("chart-line")#, + # mod_analysis_ui("app") + ), + bslib::nav_spacer(), + bslib::nav_menu( + title = "Links", + align = "right", + bslib::nav_item( + htmltools::tags$a( + shiny::icon("github"), "GitHub", + href = .app_info$repo_url, + target = "_blank" + ) + ), + bslib::nav_item( + htmltools::tags$a( + shiny::icon("book"), "Documentation", + href = .app_info$docs_url, + target = "_blank" + ) + ), + bslib::nav_item( + htmltools::tags$a( + shiny::icon("envelope"), "Contact", + href = "#", + target = "_blank" + ) + ) + ), + bslib::nav_menu( + title = "Logout", + align = "right", + bslib::nav_item( + htmltools::tags$a( + shiny::icon("sign-out-alt"), "Logout", + href = "#", + target = "_blank" + ) + ) + ) + ) + ) + +} + + diff --git a/R/mod_sidebar.R b/R/mod_sidebar.R new file mode 100644 index 0000000..9299b3d --- /dev/null +++ b/R/mod_sidebar.R @@ -0,0 +1,128 @@ + +# ------------------------------------------------------------------------ +# +# Title : App Sidebar Module +# By : Jimmy Briggs +# Date : 2024-11-08 +# +# ------------------------------------------------------------------------ + +.app_choices <- list( + properties = c("Property 1", "Property 2", "Property 3", "Property 4") +) + +# topic ------------------------------------------------------------------- + +#' App Sidebar Module +#' +#' @name mod_sidebar +#' +#' @description +#' This module creates a sidebar for the app that contains filters, options, and about information. +#' +#' It includes the UI and server functions: +#' +#' - `mod_sidebar_ui()` +#' - `mod_sidebar_server()` +#' +#' @param id The module id. +#' @param ... Additional parameters. +#' +#' @return +#' - `mod_sidebar_ui()`: A shiny UI function. +#' - `mod_sidebar_server()`: A shiny server function. + + +# UI ---------------------------------------------------------------------- + +#' @rdname mod_sidebar +#' @export +#' @importFrom bsicons bs_icon +#' @importFrom bslib sidebar accordion accordion_panel +#' @importFrom htmltools tags +#' @importFrom shiny NS +#' @importFrom shinyWidgets pickerInput +mod_sidebar_ui <- function(id, ...) { + + ns <- shiny::NS(id) + + bslib::sidebar( + htmltools::tags$div( + class = "sidebar-title", + htmltools::tags$h5("Sidebar"), + htmltools::tags$p("Use the sidebar for filtering and other controls.") + ), + bslib::accordion( + id = ns("accordion"), + bslib::accordion_panel( + title = "Filters", + value = ns("filters"), + icon = bsicons::bs_icon("filter"), + htmltools::tags$div( + class = "text-center", + shinyWidgets::pickerInput( + ns("properties"), + label = icon_text("building", "Select Properties"), + choices = .app_choices$properties, + multiple = TRUE, + options = list( + `actions-box` = TRUE, + `live-search` = TRUE, + `live-search-normalize` = TRUE, + `live-search-placeholder` = 'Search...', + `selected-text-format` = 'count > 3', + `count-selected-text` = 'Properties Selected' + ) + ) + ), + bslib::accordion_panel( + title = "Options", + value = ns("options"), + icon = bsicons::bs_icon("gear"), + htmltools::tags$div( + class = "text-center"#, + # TODO: Add options here + ) + ) + ), + bslib::accordion_panel( + title = "About", + value = ns("about"), + icon = bsicons::bs_icon("info"), + htmltools::tags$div( + class = "text-center", + htmltools::tags$p("App Version: 0.0.1", align = "center"), + htmltools::tags$p("Author: No Clocks, LLC", align = "center"), + htmltools::tags$p("Date: 2024-11-08", align = "center") + ) + ) + ) + ) + +} + +# server ------------------------------------------------------------------ + +#' @rdname mod_sidebar +#' @export +#' @importFrom shiny moduleServer reactive req +mod_sidebar_server <- function(id, ...) { + + shiny::moduleServer( + id, + function(input, output, session) { + + # Server Logic + out <- shiny::reactive({ + shiny::req(input$properties) + list( + properties = input$properties + ) + }) + + # Return Reactive Values with Options and Filters + return(out) + + } + ) +} diff --git a/R/mod_title.R b/R/mod_title.R new file mode 100644 index 0000000..d422598 --- /dev/null +++ b/R/mod_title.R @@ -0,0 +1,34 @@ + +# ------------------------------------------------------------------------ +# +# Title : App Title Module +# By : Jimmy Briggs +# Date : 2024-11-08 +# +# ------------------------------------------------------------------------ + +mod_title_ui <- function(id, ...) { + + ns <- shiny::NS(id) + + htmltools::tags$div( + id = ns("title"), + class = "navbar-brand", + htmltools::tags$a( + href = "#", + htmltools::tags$img( + src = .app_info$logo, + alt = .app_info$name, + height = 50, + width = "auto" + ) + ) + ) + +} + +mod_title_server <- function(id, ...) { + shiny::server <- function(input, output, session) { + # No server logic needed + } +} diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..9690da5 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,14 @@ + +# ------------------------------------------------------------------------ +# +# Title : Utilities +# By : Jimmy Briggs +# Date : 2024-11-08 +# +# ------------------------------------------------------------------------ + +icon_text <- function(icon, text, .function = shiny::icon) { + if (is.character(icon)) i <- .function(icon) else i <- icon + t <- paste0(" ", text) + htmltools::tagList(htmltools::tags$div(i, t)) +} diff --git a/dev/R/app_ui.R b/dev/R/app_ui.R deleted file mode 100644 index e69de29..0000000 diff --git a/dev/R/mod_sidebar.R b/dev/R/mod_sidebar.R deleted file mode 100644 index e69de29..0000000 diff --git a/dev/R/utils.R b/dev/R/utils.R deleted file mode 100644 index e69de29..0000000 diff --git a/man/mod_sidebar.Rd b/man/mod_sidebar.Rd new file mode 100644 index 0000000..183856e --- /dev/null +++ b/man/mod_sidebar.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mod_sidebar.R +\name{mod_sidebar} +\alias{mod_sidebar} +\alias{mod_sidebar_ui} +\alias{mod_sidebar_server} +\title{App Sidebar Module} +\usage{ +mod_sidebar_ui(id, ...) + +mod_sidebar_server(id, ...) +} +\arguments{ +\item{id}{The module id.} + +\item{...}{Additional parameters.} +} +\value{ +\itemize{ +\item \code{mod_sidebar_ui()}: A shiny UI function. +\item \code{mod_sidebar_server()}: A shiny server function. +} +} +\description{ +This module creates a sidebar for the app that contains filters, options, and about information. + +It includes the UI and server functions: +\itemize{ +\item \code{mod_sidebar_ui()} +\item \code{mod_sidebar_server()} +} +}