From c607c503288a94e63dfa5fe482dc1b765aad15dc Mon Sep 17 00:00:00 2001 From: alex-rogers-hub Date: Fri, 14 Feb 2025 16:19:41 +0000 Subject: [PATCH 1/2] Initial commit, adding reset to refresh on custom disconnect message (#95) * Initial commit, adding reset to refresh on custom disconnect message * double refresh * document() ! * cleaning updates * proj commit * add all() to valid check to allow for lists of urls like previous behaviour * params updated * comments in document() --- R/custom_disconnect_message.R | 50 +++++++++++++++---- R/validation.R | 2 +- dfeshiny.Rproj | 45 ++++++++--------- man/custom_disconnect_message.Rd | 10 +++- tests/test_dashboard/server.R | 2 +- .../testthat/test-custom_disconnect_message.R | 10 ++++ 6 files changed, 82 insertions(+), 37 deletions(-) diff --git a/R/custom_disconnect_message.R b/R/custom_disconnect_message.R index 51c4c17..ea81611 100644 --- a/R/custom_disconnect_message.R +++ b/R/custom_disconnect_message.R @@ -5,6 +5,7 @@ #' Create the HTML overlay panel to appear when a user loses connection to a dashboard. #' #' @param refresh the text to appear that will refresh the page when clicked +#' @param reset the text to appear that will reset the page when clicked #' @param links A vector of possible URLs for the public site. Should mostly just be a single URL, #' but can be two URLs if an overflow site has been set up #' @param publication_name The parent publication name @@ -16,6 +17,7 @@ #' @param custom_refresh Custom refresh link, defaults to refreshing the page, main value is if you #' have bookmarking enabled and want the refresh to send to the initial view instead of reloading #' any bookmarks +#' @param custom_reset Custom reset link, defaults to resetting the page #' #' @importFrom htmltools tags tagList #' @@ -49,22 +51,17 @@ #' custom_refresh = "https://department-for-education.shinyapps.io/my-dashboard" #' ) custom_disconnect_message <- function( - refresh = "Refresh page", + refresh = "refresh page (attempting to keep your last known selections)", + reset = "reset page (removing any previous selections)", dashboard_title = NULL, links = NULL, publication_name = NULL, publication_link = NULL, support_contact = "explore.statistics@education.gov.uk", - custom_refresh = NULL) { + custom_refresh = NULL, + custom_reset = NULL) { # Check links are valid - is_valid_sites_list <- function(sites) { - lapply( - stringr::str_trim(sites), startsWith, - "https://department-for-education.shinyapps.io/" - ) - } - - if (FALSE %in% is_valid_sites_list(links) || + if (FALSE %in% validate_dashboard_url(links) || "https://department-for-education.shinyapps.io/" %in% links) { # nolint: [indentation_linter] stop("You have entered an invalid site link in the links argument.") } @@ -84,6 +81,21 @@ custom_disconnect_message <- function( } } + if (!is.null(custom_reset)) { + is_valid_reset <- function(reset) { + startsWith(stringr::str_trim(reset), "https://department-for-education.shinyapps.io/") + } + + if (is_valid_reset(custom_reset) == FALSE) { + stop( + paste0( + "You have entered an invalid site link in the custom_reset argument. It must be a site", + " on shinyapps.io." + ) + ) + } + } + pub_prefix <- c( "https://explore-education-statistics.service.gov.uk/find-statistics/", "https://www.explore-education-statistics.service.gov.uk/find-statistics/", @@ -107,6 +119,7 @@ custom_disconnect_message <- function( # TODO: Add email validation once a11y panel PR is in checkmate::assert_string(refresh) + checkmate::assert_string(reset) # Attach CSS from inst/www/css/visually-hidden.css dependency <- htmltools::htmlDependency( @@ -165,6 +178,23 @@ custom_disconnect_message <- function( .noWS = c("after") ) }, + ", or ", + if (is.null(custom_reset)) { + tags$a( + id = "ss-reset-link", + href = "#", + reset, + onclick = "window.location.reload(false);", + .noWS = c("after") + ) + } else { + tags$a( + id = "ss-reset-link", + href = custom_reset, + reset, + .noWS = c("after") + ) + }, "." ), if (length(links) > 1) { diff --git a/R/validation.R b/R/validation.R index 0265756..d654c23 100644 --- a/R/validation.R +++ b/R/validation.R @@ -48,7 +48,7 @@ validate_dashboard_url <- function(url) { as.character(url), ignore.case = TRUE ) - if (!valid) { + if (!all(valid)) { stop(paste(url, "is not a valid DfE dashboard deployment URL")) } } diff --git a/dfeshiny.Rproj b/dfeshiny.Rproj index 0af6124..69fafd4 100644 --- a/dfeshiny.Rproj +++ b/dfeshiny.Rproj @@ -1,23 +1,22 @@ -Version: 1.0 -ProjectId: 542ddaed-ab53-4f0c-8930-7994a4453a0d - -RestoreWorkspace: No -SaveWorkspace: No -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 2 -Encoding: UTF-8 - -RnwWeave: Sweave -LaTeX: pdfLaTeX - -AutoAppendNewline: Yes -StripTrailingWhitespace: Yes -LineEndingConversion: Posix - -BuildType: Package -PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source -PackageRoxygenize: rd,collate,namespace +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes +LineEndingConversion: Posix + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace diff --git a/man/custom_disconnect_message.Rd b/man/custom_disconnect_message.Rd index 94c6b0e..a3dd484 100644 --- a/man/custom_disconnect_message.Rd +++ b/man/custom_disconnect_message.Rd @@ -5,18 +5,22 @@ \title{Custom disconnect message} \usage{ custom_disconnect_message( - refresh = "Refresh page", + refresh = "refresh page (attempting to keep your last known selections)", + reset = "reset page (removing any previous selections)", dashboard_title = NULL, links = NULL, publication_name = NULL, publication_link = NULL, support_contact = "explore.statistics@education.gov.uk", - custom_refresh = NULL + custom_refresh = NULL, + custom_reset = NULL ) } \arguments{ \item{refresh}{the text to appear that will refresh the page when clicked} +\item{reset}{the text to appear that will reset the page when clicked} + \item{dashboard_title}{Title of the dashboard} \item{links}{A vector of possible URLs for the public site. Should mostly just be a single URL, @@ -33,6 +37,8 @@ explore.statistics@education.gov.uk} \item{custom_refresh}{Custom refresh link, defaults to refreshing the page, main value is if you have bookmarking enabled and want the refresh to send to the initial view instead of reloading any bookmarks} + +\item{custom_reset}{Custom reset link, defaults to resetting the page} } \value{ A HTML overlay panel that appears when a user loses connection to a DfE R Shiny diff --git a/tests/test_dashboard/server.R b/tests/test_dashboard/server.R index a9bf5fe..2ac8253 100644 --- a/tests/test_dashboard/server.R +++ b/tests/test_dashboard/server.R @@ -17,6 +17,6 @@ server <- function(input, output, session) { ) output$reactable_example <- reactable::renderReactable( - dfe_reactable(mtcars |> dplyr::select("mpg", "cyl", "hp", "gear")) + dfe_reactable(mtcars |> dplyr::select("mpg", "cyl", "hp", "gear")) ) } diff --git a/tests/testthat/test-custom_disconnect_message.R b/tests/testthat/test-custom_disconnect_message.R index dbb1888..c8318a6 100644 --- a/tests/testthat/test-custom_disconnect_message.R +++ b/tests/testthat/test-custom_disconnect_message.R @@ -179,3 +179,13 @@ test_that("Can customise refresh link, but not too much", { ) ) }) + + +test_that("Reset and Refresh links appear", { + expect_no_error( + custom_disconnect_message( + refresh = "Refresh page", + reset = "Reset page" + ) + ) +}) From 969aae96911908dfee0bf35a1315f9f376bdabd5 Mon Sep 17 00:00:00 2001 From: Rich Bielby Date: Mon, 17 Feb 2025 13:12:31 +0000 Subject: [PATCH 2/2] Updated lint workflow using usethis::use_github_action('lint') (#97) * Updated lint workflow using usethis::use_github_action('lint') * Added cyclocomp as explicit requirement in lintr workflow * Trying to force lintr to the previous working version as 3.2 is broken due to change in required tests * Removing yaml ref in deploy vignette code chunks * Removed wrong refernce in a11y panel --- .github/workflows/lint.yaml | 36 ++++++++++++ .github/workflows/lintr.yml | 56 ------------------- .../using-the-dfeshiny-deploy-template.Rmd | 4 +- 3 files changed, 38 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/lint.yaml delete mode 100644 .github/workflows/lintr.yml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..b6ca678 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,36 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + +name: lint.yaml + +permissions: read-all + +jobs: + lint: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::lintr, local::. + + - name: Lint + run: | + # Pin the lintr version to avoid breaking changes with newer 3.2.0 version + # See: https://github.com/apache/arrow/pull/45524 + pak::pak("lintr@3.1.2") + lintr::lint_package() + shell: Rscript {0} + env: + LINTR_ERROR_ON_LINT: true diff --git a/.github/workflows/lintr.yml b/.github/workflows/lintr.yml deleted file mode 100644 index 4abb5b2..0000000 --- a/.github/workflows/lintr.yml +++ /dev/null @@ -1,56 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# lintr provides static code analysis for R. -# It checks for adherence to a given style, -# identifying syntax errors and possible semantic issues, -# then reports them to you so you can take action. -# More details at https://lintr.r-lib.org/ - -name: lintr - -on: - push: - branches: [ "main" ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ "main" ] - schedule: - - cron: '23 5 * * 3' - -permissions: - contents: read - -jobs: - lintr: - name: Run lintr scanning - runs-on: ubuntu-latest - permissions: - contents: read # for checkout to fetch code - security-events: write # for github/codeql-action/upload-sarif to upload SARIF results - actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - uses: r-lib/actions/setup-r@v2 - with: - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: any::lintr, local::. - needs: lint - - - name: Run lintr - run: lintr::sarif_output(lintr::lint_dir("."), "lintr-results.sarif") - shell: Rscript {0} - continue-on-error: true - - - name: Upload analysis results to GitHub - uses: github/codeql-action/upload-sarif@v3 - with: - sarif_file: lintr-results.sarif - wait-for-processing: true diff --git a/vignettes/using-the-dfeshiny-deploy-template.Rmd b/vignettes/using-the-dfeshiny-deploy-template.Rmd index 4abd71f..8abec93 100644 --- a/vignettes/using-the-dfeshiny-deploy-template.Rmd +++ b/vignettes/using-the-dfeshiny-deploy-template.Rmd @@ -43,7 +43,7 @@ At the root of your project, add a file called `deploy_parameters.yaml`.\ Below is an example with optional parameters: -```{yaml} +``` dashboard_name: "my-cool-dashboard" deploy_target: "shinyapps" ``` @@ -62,7 +62,7 @@ reusable workflow. Here is a minimal example: -```{yaml} +``` name: Deploy Dashboard on: