Skip to content

Commit

Permalink
Merge branch 'master' into fix-header-logo-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mzayeddfe authored Dec 12, 2024
2 parents 0856309 + cfe5cfb commit 946f836
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 30 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
^pkgdown$
^\.github$
^LICENSE\.md$
_\.new\.png$
34 changes: 34 additions & 0 deletions .github/workflows/showcase-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
push:
branches:
- main
- master

name: Showcase app deploy

jobs:
deployShiny:
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

- name: Load packages and push to shinyapps.io
shell: Rscript {0}
run: |
if (!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools")
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
renv::install("shinyjs")
devtools::install()
devtools::load_all()
renv::install("rsconnect")
rsconnect::setAccountInfo(name = 'department-for-education', token = '${{secrets.SHINYAPPS_TOKEN}}', secret = '${{secrets.SHINYAPPS_SECRET}}')
shiny_app <- run_example()
rsconnect::deployApp(shiny_app, forceUpdate = TRUE)
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.RData
.DS_Store
docs/
# {shinytest2}: Ignore new debug snapshots for `$expect_values()`
*_.new.png
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Imports:
shinyjs,
stringr
Suggests:
testthat
testthat,
shinytest2
Encoding: UTF-8
RoxygenNote: 7.3.2
36 changes: 15 additions & 21 deletions R/run_example.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Example Function
#'
#' This function runs a shiny example using different parts of the package
#' This function runs a shiny example showcasing different parts of the package
#'
#' @return a shiny app with examples in
#' @keywords example
#' @export
Expand All @@ -27,6 +28,7 @@ run_example <- function() {
shiny::shinyApp(
ui = shiny::fluidPage(
title = "ShinyGovstyle",

cookieBanner("Run Example"),
skip_to_main(),
header("MOJ", "ShinyGovstyle Example",
Expand All @@ -36,18 +38,13 @@ run_example <- function() {
banner(
"banner",
"Beta",
'This is a new service \u002D your <a class="govuk-link" href="#">

'This is a new service \u002D your <a class="govuk-link" href="https://github.com/dfe-analytical-services/shinyGovstyle/issues/new/choose">
feedback</a> will help us to improve it.'
),

# Need this to make the error and word count work
shinyjs::useShinyjs(),

# Add a message to show users how to see this code
shiny::tags$br(),
shiny::markdown(
"Run ```View(run_example)``` in console to see the code for this app"
),
gov_row(
# Nav columns
shiny::column(
Expand Down Expand Up @@ -119,6 +116,12 @@ run_example <- function() {
width = 9,
id = "main_col", # DO NOT REMOVE ID

shiny::tags$br(),
shiny::markdown(
"If running locally, run ```View(run_example)``` in console to see the code for this app. Otherwise, you can see the <a href='https://github.com/dfe-analytical-services/shinyGovstyle/blob/master/R/run_example.R/'>latest version of the code on GitHub</a>."
),


# Set up a nav panel so everything not on single page
shiny::tabsetPanel(
type = "hidden",
Expand All @@ -142,7 +145,7 @@ run_example <- function() {
),
heading_text("radio_button_Input (stacked)", size = "s"),
radio_button_Input(
inputId = "name_changed", label = "Have you changed your name?",
inputId = "name_changed_stacked", label = "Have you changed your name?",
choices = c("Yes", "No"), inline = FALSE,
hint_label = "This includes changing your last name or spelling
your name differently."
Expand Down Expand Up @@ -213,8 +216,8 @@ run_example <- function() {
word_limit = 300
),
heading_text("button_Input", size = "s", id = "button_input_text_types"),
button_Input("btn2", "Go to next page"),
button_Input("btn3", "Check for errors", type = "warning")
button_Input("btn_error", "Check for errors", type = "warning")

)
),

Expand All @@ -237,7 +240,6 @@ run_example <- function() {
heading_text("govTabs", size = "s"),
shinyGovstyle::govTabs("tabsID", data, "tabs"),
heading_text("button_Input", size = "s", id = "button_input_tables_tabs_accordions"),
button_Input("btn4", "Go to next page"),
heading_text("accordions", size = "s"),
shinyGovstyle::accordion(
"acc1",
Expand Down Expand Up @@ -407,22 +409,14 @@ run_example <- function() {
shiny::updateTabsetPanel(session, "tab-container", selected = "text_types")
})

shiny::observeEvent(input$btn1, {
shiny::updateTabsetPanel(session, "tab-container", selected = "tables_tabs_and_accordions")
})

shiny::observeEvent(input$btn1, {
shiny::updateTabsetPanel(session, "tab-container", selected = "feedback_types")
})

# Need this to use live update the word counter
shiny::observeEvent(
input$text_area2,
word_count("text_area2", input$text_area2)
)

# Trigger error if text_are2 is blank
shiny::observeEvent(input$btn3, {
shiny::observeEvent(input$btn_error, {
if (input$text_area2 == "") {
error_on("text_area2")
} else {
Expand Down
18 changes: 10 additions & 8 deletions tests/testthat/test-run_example.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
library(shinytest2)

test_that("shiny example loads", {
shiny::testServer(
app = run_example(), {
expect_equal(
session$isClosed(),
FALSE
)
test_that("App loads and title of app appears as expected", {
# Don't run these tests on the CRAN build servers
skip_on_cran()

}
shiny_app <- run_example()
app <- AppDriver$new(shiny_app, name = "showcase")

expect_equal(
app$get_text("title"),
"ShinyGovstyle"
)
})

0 comments on commit 946f836

Please sign in to comment.