Skip to content

Commit

Permalink
Merge pull request #59 from dfe-analytical-services/improve-support-f…
Browse files Browse the repository at this point in the history
…eedback-tab

Improve support feedback tab
  • Loading branch information
mzayeddfe authored Oct 25, 2024
2 parents d67ffe7 + 8b4cff4 commit e8cb976
Show file tree
Hide file tree
Showing 10 changed files with 673 additions and 80 deletions.
25 changes: 13 additions & 12 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dfeshiny
Title: DfE R Shiny Standards
Version: 0.4.3
Version: 0.5.0
Authors@R: c(
person("Rich", "Bielby", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9070-9969")),
Expand All @@ -10,33 +10,34 @@ Authors@R: c(
Description: R package containing preferred methods for creating official
DfE R-Shiny dashboards.
License: GPL (>= 3)
URL: https://dfe-analytical-services.github.io/dfeshiny/
https://www.github.com/dfe-analytical-services/dfeshiny/
Depends:
R (>= 2.10)
Imports:
magrittr,
checkmate,
glue,
htmltools,
magrittr,
RCurl,
shiny,
shinyGovstyle,
shinyjs,
stringr,
styler
Suggests:
devtools,
diffviewer,
knitr,
rmarkdown,
shinytest2,
devtools,
testthat (>= 3.0.0),
spelling
spelling,
testthat (>= 3.0.0)
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
URL: https://dfe-analytical-services.github.io/dfeshiny/
https://www.github.com/dfe-analytical-services/dfeshiny/
VignetteBuilder: knitr
Depends:
R (>= 2.10)
LazyData: true
Language: en-US
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(dfe_cookies_script)
export(external_link)
export(init_analytics)
export(init_cookies)
export(section_tags)
export(support_panel)
export(tidy_code)
importFrom(htmltools,tagList)
Expand Down
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# dfeshiny 0.5.0

## New features

* `custom_data_info` argument added to `support_panel()` so users can
write their own custom text in the "Find out more information on the data" section.

* `extra_text` argument added to `support_panel()` so users can add their own
sections.

* Added `section_tags()` to provide structure for the `extra_text` argument in
`support_panel()`.

* Added "this link" to the look up data for `bad_link_text`

# dfeshiny 0.4.3

* Fix bug in `external_link()` hidden warning so that it can be read by
Expand Down
129 changes: 129 additions & 0 deletions R/section_tags.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#' Create `shiny::tagList()` for HTML section
#'
#' @description
#' Create a list of tags that generate a HTML section.
#' This generates a header using `shiny::tags$h2()`
#' and a paragraph body using `shiny::tags$p()`
#'
#' This is to be used with functions in the `dfeshiny` package
#' to add extra sections to a public R Shiny dashboard in DfE
#'
#' @param heading Optional - A single text string or a `shiny::tagList()` object
#' for the heading of your paragraph
#' @param body A single text string or a `shiny::tagList()` object
#' for the body of your paragraph
#' @param h_level Specify the level for your heading, if you choose to include
#' one. Default is "h2". Available options are "h2","h3" or "h4".
#'
#' @return A list of HTML tags that contain a paragraph body and an optional heading.
#' @seealso [support_panel()]
#' @seealso [htmltools::tags]
#' @seealso [htmltools::tagList()]
#' @export
#'
#' @examples
#'
#' # Example for text heading and body
#' section_tags(
#' heading = "Heading test",
#' body = "This is a body text test"
#' )
#'
#' # Example for using a different heading level
#' section_tags(
#' heading = "Heading test",
#' body = "This is a body text test",
#' h_level = "h3"
#' )
#'
#'
#' # Example for text heading and text with other elements in the body
#'
#'
#' section_tags(
#' heading = "Heading test",
#' body = shiny::tagList(
#' "This is a body text test. Please contact us at",
#' dfeshiny::external_link(
#' href = paste0("mailto:", "team@@education.gov.uk"),
#' link_text = "team@@education.gov.uk",
#' add_warning = FALSE
#' )
#' )
#' )
#'
section_tags <- function(heading = NULL,
body,
h_level = "h2") {
# check that a body has been provided

if (missing(body)) {
stop("Please provide a single text string or a `shiny::tagList()` object for the
'body' argument")
}

# check that h_level is an accepted one

if (!h_level %in% c("h2", "h3", "h4")) {
stop("You used an unavailable h_level option.
Please use one of the following levels: 'h2','h3'or 'h4'")
}

# check for combined vector wrapping
# if a vector is provided and its length is >1 then it's a combined vector

if (is.vector(heading) && length(heading) > 1) {
stop("You provided a vector for the heading argument wrapped in c().
Please wrap it in shiny::tagList() instead.")
}

if (is.vector(body) && length(body) > 1) {
stop("You provided a vector for the body argument wrapped in c().
Please wrap it in shiny::tagList() instead.")
}

# if headings are provided, do a check for h_level
if (!is.null(heading)) {
# if h_level = "h4"
if (h_level == "h4") {
result <- shiny::tagList(
shiny::tags$h4(
heading
),
shiny::tags$p(
body
)
)
# if h_level = "h4"
} else if (h_level == "h3") {
result <- shiny::tagList(
shiny::tags$h3(
heading
),
shiny::tags$p(
body
)
)
} else {
# otherwise, use h2
result <- shiny::tagList(
shiny::tags$h2(
heading
),
shiny::tags$p(
body
)
)
}
# if no heading is provided, just output the body
} else {
result <- shiny::tagList(
shiny::tags$p(
body
)
)
}


return(result)
}
Loading

0 comments on commit e8cb976

Please sign in to comment.