Skip to content

Commit

Permalink
Closes #1659 and #1660 to use gt() instead of kbl() in our functi…
Browse files Browse the repository at this point in the history
…ons and reports (#1884)

* swap kbl with gt

* move the formating to allow gsm_gt

* get metricTable working in some sort of form

* address tests

* address warnings of ID not matching file name dont add full path

* sawp gsm_gt with gt::gt()
  • Loading branch information
zdz2101 authored Oct 14, 2024
1 parent 7d79a78 commit 3fcdbd2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
6 changes: 4 additions & 2 deletions R/Report_MetricCharts.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Report_MetricCharts <- function(lCharts, strMetricID = "", overview = FALSE) {
"barScoreJS",
"timeSeriesContinuousScoreJS",
"timeSeriesContinuousMetricJS",
"timeSeriesContinuousNumeratorJS"
"timeSeriesContinuousNumeratorJS",
"metricTable"
)

chartTypes2 <- c(
Expand All @@ -48,7 +49,8 @@ Report_MetricCharts <- function(lCharts, strMetricID = "", overview = FALSE) {
timeSeriesContinuousMetricJS = paste0(fontawesome::fa("chart-line", fill = "#337ab7"), " KRI Metric"),
timeSeriesContinuousNumeratorJS = paste0(fontawesome::fa("chart-line", fill = "#337ab7"), " Numerator"),
groupOverviewJS = paste0(fontawesome::fa("table", fill = "#337ab7"), " Group Overview"),
flagOverTimeJS = paste0(fontawesome::fa("table", fill = "#337ab7"), " Flags Over Time")
flagOverTimeJS = paste0(fontawesome::fa("table", fill = "#337ab7"), " Flags Over Time"),
metricTable = paste0(fontawesome::fa("table", fill = "#337ab7"), " Metric Table")
)

##### chart tab /
Expand Down
7 changes: 3 additions & 4 deletions R/Report_MetricTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ Report_MetricTable <- function(
return("Nothing flagged for this KRI.")
}

SummaryTable <- MetricTable %>%
kableExtra::kbl(format = "html", escape = FALSE) %>%
kableExtra::kable_styling("striped", full_width = FALSE)
MetricTable %>%
gsm_gt() %>%
fmt_sign_rag(columns = "Flag")

return(SummaryTable)
}
2 changes: 0 additions & 2 deletions R/util-MakeMetricTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ MakeMetricTable <- function(
desc(abs(.data$Score))
) %>%
dplyr::mutate(
Flag = Report_FormatFlag(.data$Flag),
dplyr::across(
dplyr::where(is.numeric),
~ round(.x, 2)
Expand All @@ -95,6 +94,5 @@ MakeMetricTable <- function(
"Flag"
))
)

return(MetricTable)
}
5 changes: 1 addition & 4 deletions R/util-MakeWorkflowList.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ MakeWorkflowList <- function(
full.names = FALSE,
recursive = bRecursive
)
names(yaml_files) <- sub("^.*/", "", names(yaml_files))

# if `strNames` is not null, subset the workflow list to only include
# files that match the character vector (`strNames`)
Expand All @@ -65,10 +66,6 @@ MakeWorkflowList <- function(
}
}

if (is.null(strNames) && strPath == "workflow") {
names(yaml_files) <- sub("^.*/", "", names(yaml_files))
}

workflows <- purrr::map2(
yaml_files,
names(yaml_files),
Expand Down
10 changes: 3 additions & 7 deletions inst/report/Report_KRI.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ knitr::opts_chunk$set(warning = FALSE, message = FALSE)

```{r, results='asis', echo=FALSE, message=FALSE, warning=FALSE}
library(gsm)
library(kableExtra)
library(gt)
setup <- Report_Setup(
dfGroups = params$dfGroups,
Expand Down Expand Up @@ -137,9 +137,6 @@ for (i in unique(params$dfMetrics$MetricID)) {
overview = FALSE
)
params$lCharts[[lMetric$MetricID]]$metricTable %>%
cat
}
```
Expand All @@ -148,11 +145,10 @@ for (i in unique(params$dfMetrics$MetricID)) {
```{r, echo=FALSE, results='asis'}
#print dfMetrics table
params$dfMetrics %>%
kbl(format="html", escape=FALSE) %>%
kable_styling ("striped", full_width = FALSE) %>%
cat
gt::gt()
```

```{r echo=FALSE}
group_dropdown <- system.file('report', 'lib', 'overallGroupDropdown.js', package = "gsm")
dropdown_drag <- system.file('report', 'lib', 'dragOverallGroupDropdown.js', package = "gsm")
Expand Down
15 changes: 7 additions & 8 deletions tests/testthat/test-Report_MetricTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@ test_that("Correct data structure when proper dataframe is passed", {
reportingResults_filt <- reportingResults %>%
dplyr::filter(MetricID == unique(reportingResults$MetricID)[1])
result <- Report_MetricTable(reportingResults_filt, reportingGroups)
expect_s3_class(result, "kableExtra")
expect_true(grepl("<table", result))
expect_true(grepl("162", result))
expect_true(grepl("Kimler", result))
expect_s3_class(result, "gt_tbl")
expect_true(any(grepl("162", result)))
expect_true(any(grepl("Kimler", result)))
})

test_that("Flag filtering works correctly", {
reportingResults_filt <- reportingResults %>%
dplyr::filter(MetricID == unique(reportingResults$MetricID)[1])
result <- Report_MetricTable(reportingResults_filt, reportingGroups)
expect_s3_class(result, "kableExtra")
expect_false(grepl("Nkaujiaong", result))
expect_s3_class(result, "gt_tbl")
expect_false(any(grepl("Nkaujiaong", result)))
})

test_that("Score rounding works correctly", {
reportingResults_filt <- reportingResults %>%
dplyr::filter(MetricID == unique(reportingResults$MetricID)[1])
result <- Report_MetricTable(reportingResults_filt, reportingGroups)
expect_true(grepl("0.05", result))
expect_true(any(grepl("0.05", result)))
})

test_that("Errors out when multiple MetricIDs passed in", {
Expand All @@ -37,5 +36,5 @@ test_that("Runs with just results with NULL group argument", {
reportingResults_filt <- reportingResults %>%
dplyr::filter(MetricID == unique(reportingResults$MetricID)[1])
result <- Report_MetricTable(reportingResults_filt)
expect_s3_class(result, "kableExtra")
expect_s3_class(result, "gt_tbl")
})

0 comments on commit 3fcdbd2

Please sign in to comment.