Skip to content

Commit

Permalink
Add superseded and deprecated highlight to reactables (#32)
Browse files Browse the repository at this point in the history
* attempt to add Deprecation and Superseded highlights to reactable tables

* Update interactive.R

* added heading

* add supersede/deprecate highlights to reactable

* remove hard-coded statuses

* add base case when no superseded and deprecated

* Update DESCRIPTION

* Update interactive.R

---------

Co-authored-by: Daniel Sjoberg <[email protected]>
  • Loading branch information
athenamelia and ddsjoberg authored Dec 7, 2023
1 parent 2bffc1e commit 3b5ef72
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Suggests:
rmarkdown,
spelling,
testthat (>= 3.2.0)
Remotes: ramnathv/htmlwidgets
VignetteBuilder:
knitr
Config/testthat/edition: 3
Expand Down
39 changes: 29 additions & 10 deletions R/interactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,26 @@ interactive_discovery <- function(type = c("gt", "reactable")) {
}

.reactable_discovery <- function() {
admiraldiscovery::discovery |>
dplyr::select(-c("package", "fn", "resource1_text")) |>
temp <- admiraldiscovery::discovery |>
dplyr::left_join(
get_admiral_deprecated() |> dplyr::mutate(deprecated = TRUE),
by = c("package", "fn")
) |>
dplyr::left_join(
get_admiral_superseded() |> dplyr::mutate(superseded = TRUE),
by = c("package", "fn")
) |>

dplyr::select(-c("package", "fn", "resource1_text"))

temp |>
reactable::reactable(
rowStyle = function(index) {
if (is.na(temp[index, "superseded"]) && is.na(temp[index, "deprecated"])) list(background = '#ffffff')
else if (temp[index, "superseded"] == TRUE) list(background = '#ffffba')
else if (temp[index, "deprecated"] == TRUE) list(background = '#ffb3ba')
},

columns = list(
dataset = reactable::colDef(
name = attr(admiraldiscovery::discovery$dataset, 'label'),
Expand Down Expand Up @@ -59,8 +76,11 @@ interactive_discovery <- function(type = c("gt", "reactable")) {
)
},
width = 150
)
),
deprecated = reactable::colDef(show = FALSE),
superseded = reactable::colDef(show = FALSE)
),

searchable = TRUE,
filterable = TRUE,
defaultPageSize = 20,
Expand All @@ -79,17 +99,17 @@ interactive_discovery <- function(type = c("gt", "reactable")) {
get_admiral_superseded() |> dplyr::mutate(superseded = TRUE),
by = c("package", "fn")
) |>
dplyr::mutate(
function_link = glue::glue("[`{package}::{fn}()`]({fn_url})"),
.after = "fn_url"
) |>
dplyr::mutate(
function_link = glue::glue("[`{package}::{fn}()`]({fn_url})"),
.after = "fn_url"
) |>
dplyr::mutate(
resource1_link = glue::glue("[{resource1_text}]({resource1_url})")
) |>
gt::gt() |>
gt::cols_hide(columns = c("fn", "fn_url", "package", "dataset_type",
"resource1_text", "resource1_url",
"deprecated", "superseded")) |>
"resource1_text", "resource1_url",
"deprecated", "superseded")) |>
gt::cols_label(
function_link = "Function",
resource1_link = "Resources"
Expand All @@ -107,7 +127,6 @@ interactive_discovery <- function(type = c("gt", "reactable")) {
gt::sub_missing(missing_text = "") |>
gt::cols_width(c(dataset, dataset_type, variable) ~ gt::pct(8)) |>
gt::cols_align(align = "left") |>
gt::tab_options(table.font.size = 11) |>
gt::opt_interactive(
use_search = TRUE,
use_filters = TRUE,
Expand Down
10 changes: 2 additions & 8 deletions vignettes/gt.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@ knitr::opts_chunk$set(
)
```

#### Variable Listing

Use the table below to identify ADaM variables and the {admiral} functions that derive them.

```{r echo=FALSE}
admiraldiscovery::interactive_discovery("gt")
```

```{r include=FALSE}
package_versions <-
c("admiral", "admiralonco", "admiralophtha", "admiralvaccine") |>
lapply(\(x) glue::glue("{x} v{packageVersion(x)}")) |>
unlist() |>
glue::glue_collapse(sep = ", ", last = ", and ")
```

#### Missing Variables

If you notice a ADaM variable that is missing, please take a moment to [file an issue on GitHub](https://github.com/pharmaverse/admiraldiscovery/issues) to have it added to the listing.
Expand Down
2 changes: 2 additions & 0 deletions vignettes/reactable.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ knitr::opts_chunk$set(
)
```

#### Variable Listing

Use the table below to identify ADaM variables and the {admiral} functions that derive them.

```{r echo=FALSE}
Expand Down

0 comments on commit 3b5ef72

Please sign in to comment.