#' user_acces_manager_ui
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @export
#'
#' @importFrom shiny NS tagList
user_acces_manager_ui <- function(id){
ns <- NS(id)
tagList(
uiOutput(ns("admin_board"))
)
}
#' user_acces_manager Server Functions
#'
#' @export
user_acces_manager_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
#
s3_bucket <- "fair-public-content"
s3_prefix <- "user_manager_db/"
users_db_name <- "users_db"
#
output$admin_board <- renderUI({
bs4Dash::tabBox(title = "Admin Board",width = 12,
tabPanel(title = "Manage Groups",
uiOutput(ns("create_groups_box")),
uiOutput(ns("delete_groups_box"))
),
tabPanel(title = "Manage Reports",
uiOutput(ns("manage_report_access_box")),
uiOutput(ns("delete_reports_box"))
)
)
})
# groups manager
existing_groups <- reactive({
report_s3_board <- SaldaeModulesUI::connect_to_s3_board(s3_bucket = s3_bucket, s3_prefix = s3_prefix)
users_db <- pins::pin_read(board = report_s3_board,name = users_db_name)
return(users_db$groups$group_name)
})
existing_users <- reactive({
report_s3_board <- SaldaeModulesUI::connect_to_s3_board(s3_bucket = s3_bucket, s3_prefix = s3_prefix)
users_db <- pins::pin_read(board = report_s3_board,name = users_db_name)
return(users_db$users$user_name)
})
output$list_of_groups <- renderUI({
req(existing_groups())
selectInput(inputId = ns("list_of_groups"),choices = existing_groups(), label = "List of Groups" , multiple = FALSE)
})
output$group_name <- renderUI({
textInput(inputId = ns("group_name"), label = "Group Name" , value = "")
})
output$group_description <- renderUI({
textInput(inputId = ns("group_description"), label = "Group Description" , value = "")
})
output$create_group <- renderUI({
req(input$group_name)
req(input$group_description)
actionButton(inputId = ns("create_group"), label = "Create Group" , icon = NULL, width = NULL)
})
output$delete_group <- renderUI({
req(input$list_of_groups)
actionButton(inputId = ns("create_group"), label = "Delete Group" , icon = NULL, width = NULL)
})
observeEvent(input$create_group,{
report_s3_board <- connect_to_s3_board(s3_bucket = s3_bucket, s3_prefix = s3_prefix)
users_db <- pins::pin_read(board = report_s3_board,name = users_db_name)
users_db <- create_users_group(users_db = users_db, group_name = input$group_name, group_description = input$group_description)
pins::pin_write(board = report_s3_board,x = users_db, name = users_db_name,type = "rds")
shinyalert::shinyalert(title = "Group Creation", text =" Successful", type = "success")
})
observeEvent(input$delete_group,{
report_s3_board <- connect_to_s3_board(s3_bucket = s3_bucket, s3_prefix = s3_prefix)
users_db <- pins::pin_read(board = report_s3_board,name = users_db_name)
users_db <- delete_users_group(users_db = users_db, target_group = input$group_name)
pins::pin_write(board = report_s3_board,x = users_db, name = users_db_name,type = "rds")
})
output$create_groups_box <- renderUI({
bs4Dash::box(title = "Create",collapsible = TRUE, closable = FALSE, collapsed = TRUE,status = "info",solidHeader=TRUE,
fluidRow(
column(width = 4, uiOutput(ns("group_name"))),
column(width = 4, uiOutput(ns("group_description")))
),
fluidRow(
column(width = 3, uiOutput(ns("create_group")))
)
)
})
output$delete_groups_box <- renderUI({
bs4Dash::box(title = "Delete",collapsible = TRUE, closable = FALSE, collapsed = TRUE,status = "warning",solidHeader=TRUE,
fluidRow(
column(width = 3, uiOutput(ns("list_of_groups")))
),
fluidRow(
column(width = 3, uiOutput(ns("delete_group")))
)
)
})
output$list_of_groups_users <- renderUI({
req(existing_groups())
req(existing_users())
groups_and_users <- c(existing_users(),existing_groups())
selectInput(inputId = ns("list_of_groups_users"),label = "Groups/Users", choices = groups_and_users, selected= NULL, multiple = TRUE )
})
output$grant_access_to_report <- renderUI({
actionButton(inputId = ns("grant_access_to_report"), label = "Grant Access")
})
output$manage_report_access_box <- renderUI({
bs4Dash::box(title = "Grant Access",collapsible = TRUE, closable = FALSE, collapsed = TRUE,status = "info",solidHeader=TRUE,
fluidRow(
column(width = 4, uiOutput(ns("list_of_groups_users")))
),
fluidRow(
column(width = 4, uiOutput(ns("grant_access_to_report")))
)
)
})
})
}
# ui <- function(id){
# tagList(
# user_acces_manager_ui(id = "test")
# )
# }
#
# server <- function(input, output, session){
# user_acces_manager_server(id ="test")
# }
#
# shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.