Skip to content

Commit

Permalink
feat: add initial UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jimbrig committed Nov 8, 2024
1 parent b011b1b commit 829ba72
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 0 deletions.
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
110 changes: 110 additions & 0 deletions R/app_ui.R
Original file line number Diff line number Diff line change
@@ -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"
)
)
)
)
)

}


128 changes: 128 additions & 0 deletions R/mod_sidebar.R
Original file line number Diff line number Diff line change
@@ -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)

}
)
}
34 changes: 34 additions & 0 deletions R/mod_title.R
Original file line number Diff line number Diff line change
@@ -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
}
}
14 changes: 14 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -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))
}
Empty file removed dev/R/app_ui.R
Empty file.
Empty file removed dev/R/mod_sidebar.R
Empty file.
Empty file removed dev/R/utils.R
Empty file.
32 changes: 32 additions & 0 deletions man/mod_sidebar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 829ba72

Please sign in to comment.