diff --git a/DESCRIPTION b/DESCRIPTION index 952cadb..1755db4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,15 +1,17 @@ Package: connectViz Title: Visualize Your 'RStudio Connect' Server Usage Data Version: 0.0.0.9146 -Authors@R: - person("David", "Granjon", , "dgranjon@ymail.com", role = c("aut", "cre")) +Authors@R: c( + person("David", "Granjon", , "dgranjon@ymail.com", role = c("aut", "cre")), + person(given = "Christophe", family = "Regouby", role = c("ctb"), email = "christophe.regouby@airbus.com") + ) Description: A collection of helper functions and 'htmlwidgets' to help admins or user better understand how 'RStudio Connect' is used in their organization. The package provides plug and play visualizations that can be customized depending on needs. License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.3 Suggests: testthat (>= 3.0.0), shinydashboard diff --git a/NAMESPACE b/NAMESPACE index 9e25e3e..5ae87f8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -28,6 +28,7 @@ export(process_rsc_content) export(process_rsc_user) export(sort_content_by_access) export(sort_content_by_appmode) +export(sort_content_by_pyversion) export(sort_content_by_rversion) export(sort_users_by_role) import(apexcharter) diff --git a/R/helpers-data.R b/R/helpers-data.R index ba503a0..808b84b 100644 --- a/R/helpers-data.R +++ b/R/helpers-data.R @@ -444,7 +444,21 @@ sort_content_by_rversion <- function(content) { mutate(Percentage = round(n / sum(n) * 100, 1)) } - +#' Sort RStudio Connect content by python version +#' +#' +#' @param content Get from \link[connectapi]{get_content}. +#' +#' @return A tibble with content grouped by python version. +#' @export +#' @importFrom rlang .data +sort_content_by_pyversion <- function(content) { + content %>% + filter(!is.na(.data$py_version)) %>% + group_by(.data$py_version) %>% + summarize(n = n()) %>% + mutate(Percentage = round(n / sum(n) * 100, 1)) +} #' Sort RStudio Connect content by app mode #' diff --git a/R/helpers-tables.R b/R/helpers-tables.R index 8ee38f4..f70654d 100644 --- a/R/helpers-tables.R +++ b/R/helpers-tables.R @@ -35,7 +35,7 @@ generate_table <- function(logs, sparkline = FALSE, pagination = 10, height = NU color = ifelse(n > !!threshold, "white", "black") ) %>% grid_summary( - column = "n", + columns = "n", stat = "avg", label = "Mean usage: ", position = "top" diff --git a/inst/examples/simple-rmd/analysis.Rmd b/inst/examples/simple-rmd/analysis.Rmd index 2f98ecc..61e379f 100644 --- a/inst/examples/simple-rmd/analysis.Rmd +++ b/inst/examples/simple-rmd/analysis.Rmd @@ -242,6 +242,14 @@ r_versions <- card( ) ``` +```{r content-python-version} +py_versions <- card( + full_screen = TRUE, + card_header("Python versions"), + sort_content_by_pyversion(rsc_content) |> create_pie_chart("py_version") +) +``` + ```{r content-type} content_type <- card( full_screen = TRUE, @@ -256,6 +264,7 @@ layout_column_wrap( user_roles, content_access, r_versions, + py_versions, content_type ) ``` diff --git a/man/sort_content_by_pyversion.Rd b/man/sort_content_by_pyversion.Rd new file mode 100644 index 0000000..292a4ac --- /dev/null +++ b/man/sort_content_by_pyversion.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers-data.R +\name{sort_content_by_pyversion} +\alias{sort_content_by_pyversion} +\title{Sort RStudio Connect content by python version} +\usage{ +sort_content_by_pyversion(content) +} +\arguments{ +\item{content}{Get from \link[connectapi]{get_content}.} +} +\value{ +A tibble with content grouped by python version. +} +\description{ +Sort RStudio Connect content by python version +} diff --git a/tests/testthat/test-helper-charts.R b/tests/testthat/test-helper-charts.R new file mode 100644 index 0000000..b656cf6 --- /dev/null +++ b/tests/testthat/test-helper-charts.R @@ -0,0 +1,8 @@ +test_that("create_calendar_chart works with multi years", { + dates <- seq.Date(as.Date("2017-01-01"), as.Date("2018-12-31"), by = "day") + n <- rpois(length(dates), 20) + + calendar_data <- data.frame(app_name = "my_app", Date = dates, Freq = n) + + expect_error(create_calendar_chart(calendar_data), NA) +})