From 5b0c78ebae741ff24b312756dccc07d0c4eb600f Mon Sep 17 00:00:00 2001 From: Christophe REGOUBY Date: Tue, 25 Jul 2023 08:37:00 +0200 Subject: [PATCH 1/6] add `calendar_data$Date` turn `create_calendar_chart` to be multi-year --- R/helpers-charts.R | 2 ++ R/helpers-data.R | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/R/helpers-charts.R b/R/helpers-charts.R index ec101de..2f68e6f 100644 --- a/R/helpers-charts.R +++ b/R/helpers-charts.R @@ -37,8 +37,10 @@ create_calendar_chart <- function( range <- c(start_date, end_date) max <- max(calendar_data$Freq) + calendar_data$Year <- format(calendar_data$Date, "%Y") calendar_chart <- calendar_data %>% + group_by(Year) %>% e_charts(Date) %>% e_calendar(range = range) %>% e_effect_scatter(Freq, coord_system = "calendar", legend = FALSE) %>% 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 #' From ef6b0105ab13e6df8685feac085dd0813c67cf4f Mon Sep 17 00:00:00 2001 From: Christophe REGOUBY Date: Tue, 25 Jul 2023 09:20:06 +0200 Subject: [PATCH 2/6] fix a check Notes --- R/helpers-charts.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/helpers-charts.R b/R/helpers-charts.R index 2f68e6f..a44b259 100644 --- a/R/helpers-charts.R +++ b/R/helpers-charts.R @@ -37,10 +37,10 @@ create_calendar_chart <- function( range <- c(start_date, end_date) max <- max(calendar_data$Freq) - calendar_data$Year <- format(calendar_data$Date, "%Y") calendar_chart <- calendar_data %>% - group_by(Year) %>% + dplyr::mutate(Year = format(date, "%Y")) %>% + dplyr::group_by(Year) %>% e_charts(Date) %>% e_calendar(range = range) %>% e_effect_scatter(Freq, coord_system = "calendar", legend = FALSE) %>% From 31e694ddcd18444653f5644c5ad5145f03eb22c3 Mon Sep 17 00:00:00 2001 From: Christophe REGOUBY Date: Fri, 8 Dec 2023 10:09:15 +0100 Subject: [PATCH 3/6] add metadata of sort_content_by_pyversion --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/helpers-charts.R | 2 +- R/helpers-tables.R | 2 +- man/sort_content_by_pyversion.Rd | 17 +++++++++++++++++ tests/testthat/test-helper-charts.R | 8 ++++++++ 6 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 man/sort_content_by_pyversion.Rd create mode 100644 tests/testthat/test-helper-charts.R diff --git a/DESCRIPTION b/DESCRIPTION index 952cadb..f699190 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Description: A collection of helper functions and 'htmlwidgets' to help admins o 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-charts.R b/R/helpers-charts.R index a44b259..0f1c829 100644 --- a/R/helpers-charts.R +++ b/R/helpers-charts.R @@ -39,7 +39,7 @@ create_calendar_chart <- function( max <- max(calendar_data$Freq) calendar_chart <- calendar_data %>% - dplyr::mutate(Year = format(date, "%Y")) %>% + dplyr::mutate(Year = as.Date(Date, format = "%Y")) %>% dplyr::group_by(Year) %>% e_charts(Date) %>% e_calendar(range = range) %>% 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/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) +}) From 850bde8c1ee20e06420028814fb096157f2172e1 Mon Sep 17 00:00:00 2001 From: Christophe REGOUBY Date: Fri, 8 Dec 2023 10:18:32 +0100 Subject: [PATCH 4/6] update description and fix a note --- DESCRIPTION | 6 ++++-- R/helpers-charts.R | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f699190..1755db4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,10 @@ 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. diff --git a/R/helpers-charts.R b/R/helpers-charts.R index 0f1c829..421fdcc 100644 --- a/R/helpers-charts.R +++ b/R/helpers-charts.R @@ -24,7 +24,7 @@ create_calendar_chart <- function( callback = NULL ) { - Date <- Freq <- NULL + Date <- Freq <- Year <-NULL renderEcharts4r({ validate(need(nrow(calendar_data()) > 0, "No calendar data found ...")) From 0ea8aea711364bb535d2ccb4fbf98a678759044c Mon Sep 17 00:00:00 2001 From: Christophe REGOUBY Date: Fri, 8 Dec 2023 11:36:23 +0100 Subject: [PATCH 5/6] add the py_version to analysis --- inst/examples/simple-rmd/analysis.Rmd | 9 +++++++++ 1 file changed, 9 insertions(+) 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 ) ``` From 9d91ae66c697fa79ce13b777edb7554d3fa92ded Mon Sep 17 00:00:00 2001 From: Christophe REGOUBY Date: Fri, 8 Dec 2023 11:39:10 +0100 Subject: [PATCH 6/6] rollback on #12 --- R/helpers-charts.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/helpers-charts.R b/R/helpers-charts.R index a49a3cf..94a3d3c 100644 --- a/R/helpers-charts.R +++ b/R/helpers-charts.R @@ -24,7 +24,7 @@ create_calendar_chart <- function( callback = NULL ) { - Date <- Freq <- Year <-NULL + Date <- Freq <- NULL renderEcharts4r({ validate(need(nrow(calendar_data()) > 0, "No calendar data found ...")) @@ -39,8 +39,6 @@ create_calendar_chart <- function( max <- max(calendar_data$Freq) calendar_chart <- calendar_data %>% - dplyr::mutate(Year = as.Date(Date, format = "%Y")) %>% - dplyr::group_by(Year) %>% e_charts(Date) %>% e_calendar(range = range) %>% e_effect_scatter(Freq, coord_system = "calendar", legend = FALSE) %>%