Skip to content

Commit

Permalink
Add Jeff's patch!
Browse files Browse the repository at this point in the history
  • Loading branch information
aclark02-arcus committed May 3, 2024
1 parent 6a44379 commit 1e623c9
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions R/mod_metricBox.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ metricBoxServer <- function(id, title, desc, value, score = "NULL",

metric <- dbSelect("select * from metric", db_name = golem::get_golem_options('assessment_db_name'))

# Render metric.
output$metricBox_ui <- renderUI({
req(title, desc)

Expand Down Expand Up @@ -68,16 +67,17 @@ metricBoxServer <- function(id, title, desc, value, score = "NULL",
title = if_else(stringr::str_extract(session$ns(id), "\\w+") != "databaseView"
& !title %in% metric$long_name, paste0(title, "*"), title)


# define some styles prior to building card
card_style <- "max-width: 400px; max-height: 250px; padding-left: 5%; padding-right: 5%;" # overflow-y: scroll;
auto_font_out <- auto_font(value,
txt_max = val_max_nchar,
size_min = .85, size_max = 1.5
) # , num_bins = 3

body_p_style <- glue::glue("font-size: {auto_font_out}vw;")

# build the html card

# Build the card's metric visual - either an icon or a meter
if(score == "NULL" | # usually for non-riskmetric cards (like on comm or database tab)
# riskmetric cards, both value and score must be missing to show an icon
# if value is missing, but score isn't, then we need to show a meter
Expand All @@ -96,25 +96,12 @@ metricBoxServer <- function(id, title, desc, value, score = "NULL",
style = "padding-top: 40%; font-size:60px; padding-left: 20%;"
)
}

} else { # use html version (displaying riskmetric score on a meter)
display_obj <-
div(style = "padding-top: 30%; padding-left: 10%;",
metric_gauge(score = score)
)
}
if (title %in% c("Dependencies","Reverse Dependencies")){ # for dependencies/rev dep cards alone
link_button <- a(class="stretched-link",
# style = "position: relative;",
title = "Click for more details",
onclick = sprintf('(function () {
Shiny.setInputValue("%s", new Date().getTime());
}());', NS(id,"dep_click")))
}
else {
link_button <- NULL
display_obj <- div(style = "padding-top: 30%; padding-left: 10%;",
metric_gauge(score = score))
}

# Build HTML Card
html_component <- div(
class = "card mb-3 text-center border-info", style = card_style,
div(
Expand All @@ -124,7 +111,6 @@ metricBoxServer <- function(id, title, desc, value, score = "NULL",
display_obj
),
div(
link_button,
class = "col-md-8",
h5(
class = "card-header bg-transparent", style = "font-size: 1vw",
Expand All @@ -138,12 +124,16 @@ metricBoxServer <- function(id, title, desc, value, score = "NULL",
div(class = "card-footer bg-transparent", desc)
))


# Turn certain metric cards into hyperlinks that redirect to another tab (dependencies tab)
if (title %in% c("Dependencies","Reverse Dependencies")){
html_component <- shiny::tagAppendAttributes(html_component,
onMouseOver="this.style['box-shadow'] = '2px 2px 2px black';
this.style['cursor'] = 'pointer'",
onMouseOut="this.style['box-shadow'] = 'none'")
html_component <- shiny::tagAppendAttributes(
html_component,
style = "--cursor: pointer; cursor: var(--cursor)",
onMouseOver="this.style['box-shadow'] = '2px 2px 2px black'",
onMouseOut="this.style['box-shadow'] = 'none'",
onclick = sprintf('(function () {
Shiny.setInputValue("%s", new Date().getTime());
}());', NS(id,"dep_click")))
}
else {
html_component
Expand Down

0 comments on commit 1e623c9

Please sign in to comment.