library(flexdashboard) library(connectapi) library(dplyr) library(stringr) library(gt)
# check_envvars()
board <- pins::board_rsconnect() content_tbl <- board %>% pins::pin_read("<<USER_NAME>>/content_list")
df <- content_tbl %>% dplyr::select(guid, access_type, content_category, app_mode) %>% dplyr::mutate(content_category = ifelse(content_category == "", "Unknown", content_category)) %>% dplyr::mutate(content_category = stringr::str_to_title(content_category)) %>% dplyr::mutate(access_type = dplyr::case_when( access_type == "acl" ~ "ACL", access_type == "all" ~ "All", access_type == "logged_in" ~ "Logged In", TRUE ~ access_type )) %>% dplyr::mutate(content_category = ifelse(content_category == "Unknown", "", paste0(content_category, "-"))) %>% dplyr::mutate(app_mode = tolower(paste0(content_category, app_mode))) %>% dplyr::mutate(app_mode = dplyr::case_when( grepl("tensorflow", app_mode) ~ "tensorflow", app_mode == "shiny-shiny" ~ "shiny", app_mode == "api-api" ~ "api", app_mode == "static-static" ~ "static", TRUE ~ app_mode )) %>% dplyr::group_by(access_type, app_mode) %>% dplyr::summarize(Count = n(), .groups = "drop") %>% dplyr::arrange(access_type, desc(Count)) %>% dplyr::group_by(access_type) %>% dplyr::mutate(Pct = Count / sum(Count)) %>% dplyr::ungroup()
# Include a toggle button that switches between different gt tables: (1) with counts, and # (2) with percentages # Want to have a drilldown where if you press a column button (we need to make the columns as # buttons) then we get a view of the detailed information for All, Logged In, and ACL # Table with counts df %>% dplyr::select(-Pct) %>% tidyr::pivot_wider(names_from = access_type, values_from = Count) %>% dplyr::select(app_mode, All, `Logged In`, ACL) %>% gt::gt(rowname_col = "app_mode") %>% gt::tab_header( title = "Sharing Settings", subtitle = "RStudio Connect Server Content Audit" ) %>% gt::fmt_missing(columns = everything(), missing_text = "0") %>% gt::cols_width(1 ~ gt::px(200), everything() ~ gt::px(89)) %>% gt::opt_all_caps() %>% gt::opt_vertical_padding(scale = 0.65) %>% gt::opt_row_striping() %>% gt::opt_align_table_header(align = "left") # Table with Percentages df %>% dplyr::select(-Count) %>% tidyr::pivot_wider(names_from = access_type, values_from = Pct) %>% dplyr::select(app_mode, All, `Logged In`, ACL) %>% gt::gt(rowname_col = "app_mode") %>% gt::tab_header( title = "Sharing Settings", subtitle = "RStudio Connect Server Content Audit" ) %>% gt::fmt_percent(columns = everything(), decimals = 0) %>% gt::cols_width(1 ~ gt::px(200), everything() ~ gt::px(89)) %>% gt::opt_all_caps() %>% gt::opt_vertical_padding(scale = 0.65) %>% gt::opt_row_striping() %>% gt::opt_align_table_header(align = "left") %>% gt::text_transform( locations = cells_body(), fn = function(x) dplyr::case_when(x == "0%" ~ "<1%", x == "NA" ~ "0%", TRUE ~ x) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.