-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_text_formatting.R
72 lines (65 loc) · 1.92 KB
/
utils_text_formatting.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#' Generate label for input fields with unit
#'
#' @param name the parameter/initial value name
#' @param unit the unit of the parameter/initial value
#'
#' @return a string of the parameter/initial value name and its unit
field_label <- function(name, unit){
unit_out <- dplyr::case_when(unit == "logical" ~ "[-]",
is.na(unit) ~ "",
unit == "" ~ "",
.default = paste0("[",unit,"]")
)
trimws(paste0(name, " ", unit_out))
}
#' create an div container with title
#'
#' @param mytext the text to be displayed
#' @param tooltip The text that appears when the mouse hovers over `mytext`
#'
#' @return an html div-container
#'
#' @examples
#' \dontrun{
#' tooltip_text(mytext = "Tmin",
#' tooltip = get_parameter_info(
#' model_ = "Lemna_Schmitt",
#' parameter_ = "Tmin",
#' type_ ="description"
#' )
#' )
#' tooltip_text(mytext = "Tmin")
#' }
tooltip_text <- function(mytext, tooltip){
if (missing(tooltip)){
out <- paste0("<div>", mytext, "</div>")
} else {
out <- paste0("<div title='",tooltip,"'>", mytext, "</div>")
}
return(HTML(out))
}
#' Add info-icon to text
#'
#' @param mytext the main text after which the info button will appear
#' @param button_id the id of info button that can be referenced by e.g. observeEvent
#'
#' @return html object
#' @examples
#' \dontrun{
#' mytext <- "Parameters"
#' infoButtonId <- "boxinfo"
#' add_info_icon(mytext, infoButtonId)
#' }
add_info_icon <- function(mytext, button_id){
id <- sub("^(.*-).*$","\\1",button_id)
out <- htmltools::HTML(
mytext,
as.character(
actionLink(inputId = button_id,
label = "",
icon = icon("info-circle"),
class = "info-circle-link")
)
)
return(out)
}