Files
AVSDevR.ShinyApplication/R/ufDashboardApplication.R
2026-02-10 18:17:01 +00:00

112 lines
3.5 KiB
R

#' UserFrosting full dashboard R shiny application
#'
#' @export
# nolint next: object_name_linter. R6Class
UFDashboardApplication <- R6::R6Class(
"UFDashboardApplication",
inherit = UFApplication,
public = list(
#' @description Starts the application with the UserFrosting sidebar
#' collapsed by default
withSidebarCollapsed = function() {
private$sidebar_collapsed <- TRUE
invisible(self)
},
#' @description Creates the UserFrosting UI component for an R Shiny
#' application
#' @returns An R Shiny tagList for \link[shiny]{shinyApp}
ui = function() {
if (file.exists("widgets/help.R")) {
private$mHelp <- modules::use("widgets/help.R")
}
if (file.exists("widgets/title.R")) {
private$mDashboardTitle <- modules::use("widgets/title.R")
}
if (file.exists("widgets/menu.R")) {
private$mDashboardMenu <- modules::use("widgets/menu.R")
}
# Create a UI
ui <- shinydashboard::dashboardPage(
header = shinydashboard::dashboardHeader(
title = if (!is.null(private$mDashboardTitle)) {
private$mDashboardTitle$ui
} else {
private$appPage$title()
},
.list = c(
# Help links
if (!is.null(private$mHelp)) list(private$mHelp$ui("help")),
# UF stuff
if (length(private$with_users) == 0 || private$with_users) {
list(AVSDevR.UserFrosting::ufUiTopbar())
}
)
),
sidebar = shinydashboard::dashboardSidebar(
collapsed = !(
length(private$sidebar_collapsed) == 0
|| private$sidebar_collapsed == FALSE
),
shiny::div(
id = "mainSidebar",
# UF stuff
if (length(private$with_users) == 0 || private$with_users) {
AVSDevR.UserFrosting::ufUiSidebar()
},
# Normal sidebar
shinydashboard::sidebarMenu(
id = "mainMenu",
shiny::tags$li(class = "header", "NAVIGATION"),
if (!is.null(private$mDashboardMenu)) private$mDashboardMenu$ui
)
)
),
body = shinydashboard::dashboardBody(self$frameUI()),
title = private$appPage$title(),
skin = private$skin
)
# Set the language
shiny:::setLang(ui, private$language)
},
#' @description Creates the UserFrosting server component for an R Shiny
#' application
#' @param input The UI inputs bound for the session
#' @param output The UI outputs bound for the session
#' @param session The current session
#' @param ufApi The UserFrosting API instance
#' @param ufUser The UserFrosting user if authenticated and verified
#' @param ... Parameters passed into the inner application
server = function(
input, output, session, ufApi = NULL, ufUser = NULL, ...
) {
# Load help menu server (if supplied)
if (!is.null(private$mHelp)) {
shiny::callModule(private$mHelp$server, "help")
}
# Load UF server (if user support required)
if (length(private$with_users) == 0 || private$with_users) {
shiny::callModule(AVSDevR.UserFrosting::ufServer, "UF", ufApi)
}
# Launch the frame
super$server(
input, output, session, ufApi = ufApi, ufUser = ufUser, ...
)
}
),
private = list(
sidebar_collapsed = FALSE,
mHelp = NULL,
mDashboardTitle = NULL,
mDashboardMenu = NULL
)
)