Package 'shinyGovstyle'

Title: Custom Gov Style Inputs for Shiny
Description: Collection of 'shiny' application styling that are based on the GOV.UK Design System. See <https://design-system.service.gov.uk/components/> for details.
Authors: Ross Wyatt [aut], Cam Race [aut, cre], Sarah Wong [aut], Richard Bielby [ctb], Charlotte Foster [ctb], Jeni Martin [ctb], Andrew Baker [ctb]
Maintainer: Cam Race <[email protected]>
License: GPL (>= 3)
Version: 0.2.0.9000
Built: 2026-06-04 11:13:52 UTC
Source: https://github.com/dfe-analytical-services/shinygovstyle

Help Index


Accordion Function

Description

This function inserts a accordion

Usage

accordion(inputId, titles, descriptions)

Arguments

inputId

Input Id for the accordion

titles

Add the titles for the accordion

descriptions

Add the main text for the accordion

Value

an accordion HTML shiny tag object

See Also

Other Govstyle tables tabs and accordions: govReactable(), govReactable-shiny, govTable(), govTabs()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png",
    logo_alt_text = "Ministry of Justice logo"
  ),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", 'This is a new service'
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    accordion(
      "acc1",
      c(
        "Writing well for the web",
        "Writing well for specialists",
        "Know your audience",
        "How people read"
      ),
      c(
        "This is the content for Writing well for the web.",
        "This is the content for Writing well for specialists.",
        "This is the content for Know your audience.",
        "This is the content for How people read."
      )
    )
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}

if (interactive()) shiny::shinyApp(ui = ui, server = server)

Button Function

Description

This function create a gov style button

Usage

button_Input(inputId, label, type = "default")

Arguments

inputId

The input slot that will be used to access the value

label

Display label for the control, or NULL for no label

type

The type of button. Options are default, start, secondary and warning. Defaults to "default"

Value

a HTML button shiny tag object

See Also

Other Govstyle select inputs: checkbox_Input(), file_Input(), radio_button_Input(), select_Input()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    shinyGovstyle::button_Input(
      inputId = "btn1",
      label = "Continue",
      type = "default"
    )
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}

if (interactive()) shinyApp(ui = ui, server = server)

Case data

Description

Simple example dataset containing case management data, used to demonstrate tabs in the example app.

Usage

case_data

Format

A data frame with 12 rows and 4 variables:

tabs

The tab the data belongs to

case_manager

The name of the case manager

cases_open

Number of open cases

cases_closed

Number of closed cases

Source

Random data generated for the shinyGovstyle package


Checkbox Function

Description

This function inserts a checkbox group

Usage

checkbox_Input(
  inputId,
  cb_labels,
  checkboxIds,
  label,
  hint_label = NULL,
  small = FALSE,
  error = FALSE,
  error_message = NULL
)

Arguments

inputId

Input Id for the group of checkboxes

cb_labels

Add the names of the options that will appear

checkboxIds

Add the values for each checkbox

label

Insert the text for the checkbox group

hint_label

Insert optional hint/secondary text. Defaults to NULL

small

change the sizing to a small version of the checkbox. Defaults to FALSE

error

Whenever you want to include error handle on the component

error_message

If you want a default error message

Value

a checkbox HTML shiny tag object

See Also

Other Govstyle select inputs: button_Input(), file_Input(), radio_button_Input(), select_Input()

Examples

ui <- shiny::fluidPage(
  # Required for error handling function
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", 'This is a new service'),
  shinyGovstyle::gov_layout(size = "two-thirds",
    # Simple checkbox
    shinyGovstyle::checkbox_Input(
      inputId = "check1",
      cb_labels = c("Option 1", "Option 2", "Option 3"),
      checkboxIds = c("op1", "op2", "op3"),
      label = "Choice option"
    ),
    # Error checkbox
    shinyGovstyle::checkbox_Input(
      inputId = "check2",
      cb_labels = c("Option 1", "Option 2", "Option 3"),
      checkboxIds = c("op1", "op2", "op3"),
      label = "Choice option",
      hint_label = "Select the best fit",
      error = TRUE,
      error_message = "Select one"
    ),
    # Button to trigger error
    shinyGovstyle::button_Input(inputId = "submit", label = "Submit")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  # Trigger error on blank submit of eventId2
  observeEvent(input$submit, {
    if (is.null(input$check2)){
      shinyGovstyle::error_on(inputId = "check2")
    } else {
      shinyGovstyle::error_off(inputId = "check2")
    }
  })
}

if (interactive()) shinyApp(ui = ui, server = server)

Cookie Banner Function

Description

This function creates a cookie banner. You need to have shinyjs::useShinyjs() enabled for this to work. All the Ids are preset. See example for how to structure.

Usage

cookieBanner(service_name)

Arguments

service_name

Name for this service to add to banner

Value

a cookie banner HTML shiny tag object

See Also

Other Govstyle page structure: banner(), footer(), gov_layout(), header(), layouts, skip_to_main()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"),
  #Needs shinyjs to work
  shinyjs::useShinyjs(),
  shinyGovstyle::cookieBanner("The best thing"),
  shinyGovstyle::gov_layout(size = "two-thirds"),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  # Set of observeEvent to create a path through the cookie banner
  observeEvent(input$cookieAccept, {
    shinyjs::show(id = "cookieAcceptDiv")
    shinyjs::hide(id = "cookieMain")
  })

  observeEvent(input$cookieReject, {
    shinyjs::show(id = "cookieRejectDiv")
    shinyjs::hide(id = "cookieMain")
  })

  observeEvent(input$hideAccept, {
    shinyjs::toggle(id = "cookieDiv")
  })

  observeEvent(input$hideReject, {
    shinyjs::toggle(id = "cookieDiv")
  })

  observeEvent(input$cookieLink, {
    # Need to link here to where further info is located. You can use
    # updateTabsetPanel to have a cookie page for instance
  })

}
if (interactive()) shinyApp(ui = ui, server = server)

Date Input Function

Description

This function create a date input that follows GDS component

Usage

date_Input(
  inputId,
  label,
  hint_label = NULL,
  error = FALSE,
  error_message = NULL,
  day = NULL,
  month = NULL,
  year = NULL
)

Arguments

inputId

The input slot that will be used to access the value

label

Display label for the control, or NULL for no label

hint_label

Display hint label for the control, or NULL for no hint label

error

Whenever to include error components.Defaults to FALSE

error_message

Error handling message? Defaults to NULL

day

Select a default day on start up. Defaults to NULL

month

Select a default month on start up. Defaults to NULL

year

Select a default year on start up. Defaults to NULL

Value

a data input HTML shiny tag object

See Also

Other Govstyle text types: gov_list(), heading_text(), input_field(), text_Input(), text_area_Input(), word_count()

Examples

ui <- shiny::fluidPage(
  # Required for error handling function.
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", 'This is a new service'
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    # Simple date input
    shinyGovstyle::date_Input(
      inputId = "dob_input",
      label = "Please enter your birthday"
    ),
    # Error date input
    shinyGovstyle::date_Input(
      inputId = "dob_input2",
      label = "Please enter your birthday",
      hint_label = "For example, 12 11 2007",
      error = TRUE
    ),
    # Button to trigger error
    shinyGovstyle::button_Input(inputId = "submit", label = "Submit")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  # Trigger error on blank submit of dob_input2
  observeEvent(input$submit, {
    if (input$dob_input2 == "//") {
      shinyGovstyle::error_on(inputId = "dob_input2")
    } else {
      shinyGovstyle::error_off(inputId = "dob_input2")
    }
  })
}

if (interactive()) shinyApp(ui = ui, server = server)

Details Function

Description

This function create a detail component that you can click for further details.

Usage

details(inputId, label, help_text)

Arguments

inputId

The input slot that will be used to access the value

label

Main label text

help_text

Additional help information in the component. Accepts a plain character string, or shiny tag objects such as shiny::tags$b("Bold") or a shiny::tagList().

Value

a details box HTML shiny tag object

See Also

Other Govstyle feedback types: gov_summary(), insert_text(), label_hint(), noti_banner(), panel_output(), tag_Input(), value_box(), warning_text()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    shinyGovstyle::details(
      inputId = "help_div",
      label = "Help with form",
      help_text = "To complete the form you need to fill it in..."
    )
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}

if (interactive()) shinyApp(ui = ui, server = server)

Download button

Description

The download_button() provides a standard way to provide a download link, which facilitates important accessible / positive user experience elements, namely:

  • file type

  • file size

These are necessary in order for users to understand what they are downloading, both in terms of being able to decide if they are comfortable with downloading the file over their current connection and if it's in a form they're able to deal with once it is downloaded. If the exact file size is not easily determined, then it may be acceptable to provide an estimate or an upper limit.

Usage

download_button(outputId, button_label, file_type = "CSV", file_size = NULL)

Arguments

outputId

The name of the output slot that the shiny::downloadHandler() is assigned to

button_label

Text that will appear describing the download action. Vague text like 'click here' or 'here' will cause an error, as will ending in a full stop. Leading and trailing white space will be automatically trimmed. If the string is shorter than 7 characters a console warning will be thrown. There is no way to hush this other than providing more detail

file_type

The file type to be download (default: CSV)

file_size

The file size if known. Needs to be a string ending in one of KB, MB, GB or rows

Value

shiny tag object

See Also

Other Govstyle actions: download_link(), download_radios(), download_radios_handler(), external_link()

Examples

ui <- shiny::fluidPage(
  gov_text("Choose a data set to download."),
  select_Input(
    "dataset",
    "Data set",
    select_text = c("Car road tests", "New York air quality"),
    select_value = c("mtcars", "airquality")
  ),
  download_button(
    "download_data",
    "Download selected data set",
    file_size = "4 KB"
  )
)

server <- function(input, output) {
  # The requested data set
  data <- reactive({
    get(input$dataset)
  })

  output$download_data <- downloadHandler(
    filename = function() {
      # Use the selected dataset as the suggested file name
      paste0(input$dataset, ".csv")
    },
    content = function(file) {
      # Write the dataset to the `file` that will be downloaded
      write.csv(data(), file)
    }
  )
}

if (interactive()) shiny::shinyApp(ui, server)

Download with extension radios

Description

Download with extension radios

Usage

download_radios(
  id = "download_radios",
  download_type = "table",
  file_types = c("CSV", "ODS", "XLSX"),
  file_sizes = c("< 1 GB", "< 1 GB", "< 1 GB"),
  small = FALSE
)

Arguments

id

Shiny element Id. Default is "download_radios", but must be customised to be unique if multiple instances of this module are being used in a single app. Must match up to the ID of a download_radios_helper() instance in server code

download_type

Element being downloaded. Expected to be along the lines of "underlying data", "table", "current data view". Default is "table"

file_types

File formats to offer, can be any combination of "CSV", "XLSX", "ODS". Default is a vector of all 3

file_sizes

Estimated file sizes for each file format. This needs to be a vector of the same length as file_types

small

Set radio buttons to small size (logical, default: FALSE)

Value

UI containing radio selection and download button

See Also

Other Govstyle actions: download_button(), download_link(), download_radios_handler(), external_link()

Examples

ui <- shiny::fluidPage(
  download_radios("download_file",
    file_types = c("CSV", "ODS"),
    file_sizes = c("2 KB", "5 KB")
  )
)

server <- function(input, output, session) {
  output$download_file <- download_radios_handler(
    "download_file",
    file_name = "simple_data_frame",
    file_contents = mtcars
  )
}

if (interactive()) shinyApp(ui, server)

Download with extension radios handler

Description

Download with extension radios handler

Usage

download_radios_handler(id = "download_radios", file_name, file_contents)

Arguments

id

Shiny element Id. Default is "download_radios", but must be customised to be unique if multiple instances of this module are being used in a single app. Must match up to the ID of a download_radios() instance in UI code

file_name

Name of the file to be downloaded

file_contents

Contents to write to the download file

Value

Output for use with download_radios()

See Also

Other Govstyle actions: download_button(), download_link(), download_radios(), external_link()

Examples

ui <- shiny::fluidPage(
  download_radios("download_file",
    file_types = c("CSV", "ODS"),
    file_sizes = c("2 KB", "5 KB")
  )
)

server <- function(input, output, session) {
  output$download_file <- download_radios_handler(
    "download_file",
    file_name = "simple_data_frame",
    file_contents = mtcars
  )
}

if (interactive()) shinyApp(ui, server)

Error off Function

Description

This function turns off the the error o the component, once issues have been sorted.

Usage

error_off(inputId)

Arguments

inputId

The input Id to turn error handling on for

Value

no return value. This toggles off error CSS

See Also

Other Govstyle errors: error_on(), error_summary(), error_summary_update()

Examples

ui <- shiny::fluidPage(
  # Required for error handling function
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", 'This is a new service'
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    # Error text box
    shinyGovstyle::text_Input(
      inputId = "eventId",
      label = "Event Name",
      error = TRUE
    ),
    # Button to trigger error
    shinyGovstyle::button_Input(inputId = "submit", label = "Submit")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  # Trigger error on blank submit of eventId2
  observeEvent(input$submit, {
    if (input$eventId != "") {
      shinyGovstyle::error_off(inputId = "eventId")
    } else {
      shinyGovstyle::error_on(
        inputId = "eventId",
        error_message = "Please complete"
      )
    }
  })
}

if (interactive()) shinyApp(ui = ui, server = server)

Error on Function

Description

This function turns on the error for the component. Can be used to validate inputs.

Usage

error_on(inputId, error_message = NULL)

Arguments

inputId

The input id that you to to turn the error on for

error_message

if you want to add an additional error message Defaults to NULL, showing the original designed error message

Value

no return value. This toggles on error CSS

See Also

Other Govstyle errors: error_off(), error_summary(), error_summary_update()

Examples

ui <- shiny::fluidPage(
  # Required for error handling function
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", 'This is a new service'
  ),
  shinyGovstyle::gov_layout(size = "two-thirds",
    # Error text box
    shinyGovstyle::text_Input(
      inputId = "eventId",
      label = "Event Name",
      error = TRUE),
    # Button to trigger error
    shinyGovstyle::button_Input(inputId = "submit", label = "Submit")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  # Trigger error on blank submit of eventId2
  observeEvent(input$submit, {
    if (input$eventId != ""){
      shinyGovstyle::error_off(inputId = "eventId")
    } else {
      shinyGovstyle::error_on(
        inputId = "eventId",
        error_message = "Please complete"
      )
    }
  })
}

if (interactive()) shinyApp(ui = ui, server = server)

Error Summary Function

Description

This function loads the error summary component to display error text. This replicates the gov style error boxes linked below: https://design-system.service.gov.uk/components/error-summary/

Usage

error_summary(inputId, error_title, error_list)

Arguments

inputId

The input slot that will be used to access the value

error_title

The title for the error summary

error_list

A list of text values to be displayed in the error body

Value

an error_summary HTML shiny tag object

See Also

Other Govstyle errors: error_off(), error_on(), error_summary_update()

Examples

ui <- shiny::fluidPage(
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    error_summary(
      inputId = "errorId",
      error_title = "Error title",
      error_list = c("error item1", "error item2")
    )
  ),
  shinyGovstyle::button_Input("btn1", "Change error summary"),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  shiny::observeEvent(input$btn1, {
    error_summary_update(
      "errorId",
      c("error item1", "error item2", "error item3")
    )},
    ignoreInit = TRUE
  )
}

if (interactive()) shinyApp(ui = ui, server = server)

Error Summary Update Function

Description

This function changes the text that displays in the error summary box. Requires shinyjs::useShinyjs() to work.

Usage

error_summary_update(inputId, error_list)

Arguments

inputId

The input Id of the error summary you want to update

error_list

An updated list of text values to be displayed in the error body

Value

an update error summary box

See Also

Other Govstyle errors: error_off(), error_on(), error_summary()

Examples

ui <- shiny::fluidPage(
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    error_summary(
      inputId = "errorId",
      error_title = "Error title",
      error_list = c("error item1", "error item2")
    )
  ),
  shinyGovstyle::button_Input("btn1", "Change error summary"),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  shiny::observeEvent(input$btn1, {
    error_summary_update(
      "errorId",
      c("error item1", "error item2", "error item3")
    )
  },
  ignoreInit = TRUE
  )
}

if (interactive()) shinyApp(ui = ui, server = server)

File Input Function

Description

This function create a file upload component. It uses the basis of the shiny fileInput function, but restyles the label and adds error onto it.

Usage

file_Input(
  inputId,
  label,
  multiple = FALSE,
  accept = NULL,
  width = NULL,
  buttonLabel = "Choose file",
  placeholder = "No file chosen",
  error = FALSE,
  error_message = NULL
)

Arguments

inputId

The input slot that will be used to access the value

label

Display label for the control, or NULL for no label

multiple

Whether the user should be allowed to select and upload multiple files at once. Does not work on older browsers, including Internet Explorer 9 and earlier

accept

A character vector of MIME types; gives the browser a hint of what kind of files the server is expecting

width

The width of the input, e.g. '400px', or '100\%'

buttonLabel

The label used on the button. Can be text or an HTML tag object

placeholder

The text to show before a file has been uploaded

error

Whenever to icnlud error handling. Defaults to FALSE

error_message

Message to display on error. Defaults to NULL

Value

a file input HTML shiny tag object

See Also

Other Govstyle select inputs: button_Input(), checkbox_Input(), radio_button_Input(), select_Input()

Examples

ui <- shiny::fluidPage(
  # Required for error handling function
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", 'This is a new service'
  ),
  shinyGovstyle::gov_layout(size = "two-thirds",
    # Simple file input
    shinyGovstyle::file_Input(inputId = "file1", label = "Upload a file"),
    # Error file
    shinyGovstyle::file_Input(
      inputId = "file2",
      label = "Upload a file",
      error = TRUE
    ),
    # Button to trigger error
    shinyGovstyle::button_Input(inputId = "submit", label = "Submit")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  # Trigger error on blank submit of file2
  observeEvent(input$submit, {
    if (is.null(input$file2)){
      shinyGovstyle::error_on(inputId = "file2")
    } else {
      shinyGovstyle::error_off(
        inputId = "file2"
      )
    }
  })
}
if (interactive()) shinyApp(ui = ui, server = server)

Font Function

Description

Loads the GDS Transport font for use in your app. GDS Transport is a restricted typeface that must only be used on GOV.UK domains. If your app is not hosted on a GOV.UK domain, do not call this function — the GOV.UK Frontend CSS will fall back to Helvetica or Arial automatically.

Usage

font()

Details

See the GOV.UK typeface guidance for full details on when GDS Transport is permitted.

Value

no value returned. This loads the font CSS file

See Also

Other Govstyle styling: full_width_overrides()

Examples

ui <- shiny::fluidPage(
  font(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png")
)

server <- function(input, output, session) {}

if (interactive()) shinyApp(ui = ui, server = server)

Styling overrides for to give full width

Description

[Experimental] This is an experimental function that will likely be removed in future releases, as we work through updating the core package styling and adding full width options into the components themselves. This is not well tested and may cause unexpected styling issues when combined with components from other packages, use at your own risk.

Usage

full_width_overrides()

Value

HTML containing CSS styling overrides

See Also

Other Govstyle styling: font()

Examples

shinyGovstyle::full_width_overrides()

Page Layout Function

Description

This function loads the page layout, This doesn't work as well as the gov_main_layout and associated functions. This is being kept for now as a simpler version where grids are not needed.

Usage

gov_layout(..., inputID = "main", size = "full")

Arguments

...

include the components of the UI that you want within the main page.

inputID

ID of the main div. Defaults to "main"

size

Layout of the page. Optional are full, one-half, two-thirds, one-third and one-quarter. Defaults to "full"

Value

a HTML shiny layout div

See Also

Other Govstyle page structure: banner(), cookieBanner(), footer(), header(), layouts, skip_to_main()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(
    size = "full",
    shinyGovstyle::panel_output(
      inputId = "panel1",
      main_text = "Application Complete",
      sub_text = paste(
        "Thank you for submitting your application.",
        "Your reference is xvsiq"
      )
    ),
    shinyGovstyle::footer(full = TRUE)
  )
)

server <- function(input, output, session) {}
if (interactive()) shinyApp(ui = ui, server = server)

Gov List function

Description

Gov List function

Usage

gov_list(list, style = "none")

Arguments

list

vector of list

style

options: "none", "bullet", "number". defaults to "none"

See Also

Other Govstyle text types: date_Input(), heading_text(), input_field(), text_Input(), text_area_Input(), word_count()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples"
  ),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", 'This is a new service'
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    shinyGovstyle::heading_text("gov_list", size = "s"),
    shinyGovstyle::gov_text("List:"),
    gov_list(list = c("a", "b", "c")),
    shinyGovstyle::gov_text("Bulleted list:"),
    gov_list(list = c("a", "b", "c"), style = "bullet"),
    shinyGovstyle::gov_text("Numbered list:"),
    gov_list(list = c("one", "two", "three"), style = "number")
  )
)

server <- function(input, output, session) {}

if (interactive()) shinyApp(ui = ui, server = server)

Tabs Function

Description

This function creates a tabs based table. It requires a single dataframe with a grouping variable.

Usage

gov_summary(inputId, headers, info, action = FALSE, border = TRUE)

Arguments

inputId

The Id to access the summary list

headers

input for the row headers value

info

Summary information values for the table. Each value accepts a plain character string, or shiny tag objects such as shiny::tags$b("Bold") or a shiny::tagList(). Pass a list rather than a character vector to mix tag and string values.

action

whenever a change link is needed. Sets input to the value of the headers using lowercase and with underscore to replace gaps. Default set to FALSE

border

set if the table should have borders. Default set to TRUE

Value

a summary list table HTML shiny tag object

See Also

Other Govstyle feedback types: details(), insert_text(), label_hint(), noti_banner(), panel_output(), tag_Input(), value_box(), warning_text()

Examples

# Create an example dataset
headers <- c(
  "Name",
  "Date of birth",
  "Contact information",
  "Contact details"
)
info <- c(
  "Sarah Philips",
  "5 January 1978",
  "72 Guild Street <br> London <br> SE23 6FH",
  "07700 900457 <br> [email protected]"
)

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    shinyGovstyle::gov_summary("sumID", headers, info, action = FALSE)
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}
if (interactive()) shinyApp(ui = ui, server = server)

Interactive govTable

Description

This function is opinionated and sets table defaults that are in keeping with the wider GOV.UK design system. Some defaults are overrideable, such as highlight=TRUE and borderless=TRUE, however some are fixed, such as showSortIcon=FALSE as the default sort icon is inaccessible. Additional arguments from reactable::reactable can be passed to customise the table.

Usage

govReactable(
  df,
  right_col = NULL,
  page_size = 10,
  highlight = TRUE,
  borderless = TRUE,
  min_widths = list(),
  ...
)

Arguments

df

A dataframe used to generate the table

right_col

A vector of column names that should be right-aligned. By default, numeric data is right-aligned, and character data is left-aligned

page_size

The default number of rows displayed per page (default: 10)

highlight

Highlight table rows on hover

borderless

Remove inner borders from table

min_widths

Customise minimum column width using a list of columns and minimum width in pixels

...

Additional arguments passed to reactable::reactable

Details

This function inserts a government-styled table using reactable. You can use this in R markdown or Quarto documents, or use renderGovReactable() and govReactableOutput() for tables in R Shiny. govReactableOutput() gives the ability to add a caption, for static tables made using just govReactable(), use heading_text() to add captions to tables.

Value

A reactable HTML widget styled with GOV.UK classes

See Also

Other Govstyle tables tabs and accordions: accordion(), govReactable-shiny, govTable(), govTabs()

Examples

# Example static table using govReactable
if (interactive()) {
  govReactable(
    iris,
    right_col = c(
      "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"
    )
  )

  govReactable(
    iris,
    right_col = c(
      "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"
    ),
    highlight = FALSE,
    page_size = 5,
    min_widths = list(
      Sepal.Length = 75,
      Sepal.Width = 75,
      Petal.Length = 75,
      Petal.Width = 75
    )
  )
}

Shiny bindings for govReactable Output and render functions for using govReactable within shiny apps

Description

Shiny bindings for govReactable Output and render functions for using govReactable within shiny apps

Usage

govReactableOutput(
  output_table_name,
  caption,
  caption_size = "l",
  heading_level = "h2"
)

renderGovReactable(expr, env = parent.frame(), quoted = FALSE)

Arguments

output_table_name

Output variable to read from

caption

Adds a caption to the table as a header

caption_size

Adjust the size of caption Options are s, m, l, xl, with l as the default

heading_level

The HTML heading level for the caption (e.g., "h2", "h3", "h4", "h5"). Default is "h2"

expr

An expression that generates a reactable widget

env

The environment in which to evaluate expr

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable

Value

govReactableOutput() returns a reactable output element that can be included in a Shiny UI

renderGovReactable() returns a reactable render function that can be assigned to a Shiny output slot

See Also

Other Govstyle tables tabs and accordions: accordion(), govReactable(), govTable(), govTabs()

Examples

ui <- shiny::fluidPage(
  govReactableOutput(
    "table",
    caption = "Example table"
  )
)

server <- function(input, output, session) {
  output$table <- renderGovReactable({
    govReactable(iris)
  })
}

if (interactive()) shinyApp(ui, server)

Table Function

Description

This function inserts a gov styled table. Format is with header looking rows and columns

Usage

govTable(
  inputId,
  df,
  caption,
  caption_size = "l",
  num_col = NULL,
  width_overwrite = NULL
)

Arguments

inputId

Input Id for the table

df

expects a dataframe to create a table

caption

adds a caption to the table as a header

caption_size

adjust the size of caption. Options are s, m, l, xl, with l as the default

num_col

adds numeric class format to these columns

width_overwrite

change width. Need to include width for every column. Columns must add up to 1. Options are three-quarters, two-thirds, one-half, one-third, one-quarter. Default is NULL

Value

a table HTML shiny tag object

See Also

Other Govstyle tables tabs and accordions: accordion(), govReactable(), govReactable-shiny, govTabs()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    shinyGovstyle::govTable(
      "tab1",
      shinyGovstyle::transport_data_small,
      "Test",
      "l",
      num_col = c(2,3),
      width_overwrite = c("one-half", "one-quarter", "one-quarter")
    )
  )
)

server <- function(input, output, session) {}

if (interactive()) shinyApp(ui = ui, server = server)

Tabs Function

Description

This function creates a tabs based table. It requires a single dataframe with a grouping variable.

Usage

govTabs(inputId, df, group_col)

Arguments

inputId

The Id to access the tag

df

A single dataframe with all data. See example for structure

group_col

The column name with the groups to be used as tabs

Value

a tab table HTML shiny tag object

See Also

Other Govstyle tables tabs and accordions: accordion(), govReactable(), govReactable-shiny, govTable()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png",
    logo_alt_text = "Ministry of Justice logo"
  ),
  shinyGovstyle::gov_main_layout(
    size = "two-thirds",
    shinyGovstyle::govTabs("tabs", shinyGovstyle::case_data, "tabs")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}
if (interactive()) shinyApp(ui = ui, server = server)

Heading Text Function

Description

This function createS heading text

Usage

heading_text(text_input, size = "xl", id, level = 1)

Arguments

text_input

Text to display

size

Text size using xl, l, m, s. Defaults to xl

id

Custom header id

level

Heading level, integer between 1 and 6. Defaults to 1

Value

a heading text HTML shiny tag object

See Also

Other Govstyle text types: date_Input(), gov_list(), input_field(), text_Input(), text_area_Input(), word_count()

Examples

shinyGovstyle::heading_text("This is great text")
shinyGovstyle::heading_text("This is great text", size = "l", level = 2)

Input Field Function

Description

This function inserts number of text inputs. Useful for addresses.

Usage

input_field(
  legend,
  labels,
  inputIds,
  widths = NULL,
  types = "text",
  error = FALSE,
  error_message = NULL
)

Arguments

legend

Legend that goes above the fieldset

labels

A list of labels for the text inputs

inputIds

A list input slots that will be used to access the value

widths

control the size of the box based on number of characters required. Options are 30, 20, 10, 5, 4, 3, 2. NULL will not limit the size

types

text box types. Will default to text

error

Whenever to icnlud error handling. Defaults to FALSE

error_message

Message to display on error. Defaults to NULL

Value

a input field of HTML as a shiny tag object

See Also

Other Govstyle text types: date_Input(), gov_list(), heading_text(), text_Input(), text_area_Input(), word_count()

Examples

ui <- shiny::fluidPage(
  # Required for error handling function
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", 'This is a new service'
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    shinyGovstyle::input_field(
      legend ="List of three text boxes in a field",
      labels = c("Field 1", "Field 2", "Field 3"),
      inputIds = c("field1", "field2", "field3"),
      widths = c(30,20,10),
      error = TRUE
    ),
   # Button to trigger error
   shinyGovstyle::button_Input(inputId = "submit", label = "Submit")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  # Trigger error on blank submit of field2
  observeEvent(input$submit, {
    if (input$field2 == ""){
      shinyGovstyle::error_on(
        inputId = "field2",
        error_message = "Please complete"
      )
    } else {
      shinyGovstyle::error_off(
        inputId = "field2"
      )
    }
  })
}
if (interactive()) shinyApp(ui = ui, server = server)

Insert Text Function

Description

This function loads the insert text component to display additional information in a special format.

Usage

insert_text(inputId, content, text = lifecycle::deprecated())

Arguments

inputId

The input slot that will be used to access the value

content

Content to display on the insert. Accepts a plain character string, or shiny tag objects such as shiny::tags$b("Bold") or a shiny::tagList().

text

[Deprecated] Use content instead

Value

a insert text HTML shiny tag object

See Also

Other Govstyle feedback types: details(), gov_summary(), label_hint(), noti_banner(), panel_output(), tag_Input(), value_box(), warning_text()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    shinyGovstyle::insert_text(
      inputId = "note",
      content = paste(
        "It can take up to 8 weeks to register a lasting power of",
        "attorney if there are no mistakes in the application."
      )
    ),
    shinyGovstyle::insert_text(
      inputId = "note-rich",
      content = shiny::tagList(
        shiny::tags$b("Important: "),
        "you can also pass tag objects."
      )
    )
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}
if (interactive()) shinyApp(ui = ui, server = server)

Label with Hint Function

Description

This function inserts a label and optional hint.

Usage

label_hint(inputId, label, hint_input = NULL)

Arguments

inputId

The input slot that will be used to access the value

label

Display label for the control, or NULL for no label

hint_input

Display hint label for the control, or NULL for no hint label

Value

a label hint HTML shiny tag object

See Also

Other Govstyle feedback types: details(), gov_summary(), insert_text(), noti_banner(), panel_output(), tag_Input(), value_box(), warning_text()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    label_hint(
      inputId = "label1",
      label = "This is a label",
      hint_input = "This is a hint"
    )
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}
if (interactive()) shinyApp(ui = ui, server = server)

Page Layout Functions

Description

These function loads the page layout in a gov layout. There is a selection of components that can sit within each other. The gov_main_layout is the overarching layout. The gov_row creates a each row and gov_box creates a box within the row. The gov_text is a container for text bodies.

Usage

gov_main_layout(..., inputID = "main")

gov_row(...)

gov_box(..., size = "full")

gov_text(...)

Arguments

...

include the components of the UI that you want within the main page. These components are made to flow through each other. See example

inputID

ID of the main div. Defaults to "main"

size

size of the box in the row. Optional are full, one-half, two-thirds, one-third and one-quarter. Defaults to "full"

Value

a HTML shiny layout div

See Also

Other Govstyle page structure: banner(), cookieBanner(), footer(), gov_layout(), header(), skip_to_main()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"),
  shinyGovstyle::gov_main_layout(
    shinyGovstyle::gov_row(
      shinyGovstyle::gov_box(
        size = "full",
        shinyGovstyle::gov_text("govuk-grid-column-full")
      )
    ),
    shinyGovstyle::gov_row(
      shinyGovstyle::gov_box(
        size = "one-half",
        shinyGovstyle::gov_text("govuk-grid-column-one-half")
      ),
      shinyGovstyle::gov_box(
        size = "one-half",
        shinyGovstyle::gov_text("govuk-grid-column-one-half")
      )
    ),
    shinyGovstyle::gov_row(
      shinyGovstyle::gov_box(
        size = "one-third",
        shinyGovstyle::gov_text("govuk-grid-column-one-third")
      ),
      shinyGovstyle::gov_box(
        size = "two-third",
        shinyGovstyle::gov_text("govuk-grid-column-two-third")
      )
    ),
    shinyGovstyle::gov_row(
      shinyGovstyle::gov_box(
        size = "one-quarter",
        shinyGovstyle::gov_text("govuk-grid-column-one-quarter")
      ),
      shinyGovstyle::gov_box(
        size = "three-quarters",
        shinyGovstyle::gov_text("govuk-grid-column-three-quarters")
      )
    )
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}

if (interactive()) shinyApp(ui = ui, server = server)

Notification Banner Function

Description

This function creates a notification banner.

Usage

noti_banner(
  inputId,
  title_txt = "Important",
  body_txt = NULL,
  type = "standard"
)

Arguments

inputId

The input Id for the banner

title_txt

The wording that appears in the title

body_txt

The wording that appears in the banner body. Accepts a plain character string, or shiny tag objects such as shiny::tags$b("Bold") or a shiny::tagList().

type

The type of banner. Options are standard and success. Standard is default

Value

a notification HTML shiny tag object

See Also

Other Govstyle feedback types: details(), gov_summary(), insert_text(), label_hint(), panel_output(), tag_Input(), value_box(), warning_text()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::noti_banner(
    inputId = "banner", title_txt = "Important", body_txt = "Example text"
  )
)

server <- function(input, output, session) {}

if (interactive()) shinyApp(ui = ui, server = server)

Panel output

Description

This function inserts a panel. Normally used for confirmation screens

Usage

panel_output(inputId, main_text, sub_text)

Arguments

inputId

The input slot that will be used to access the value.

main_text

Add the header for the panel

sub_text

Add the main body of text for the panel. Accepts a plain character string, or shiny tag objects such as shiny::tags$b("Bold") or a shiny::tagList().

Value

a panel HTML shiny tag object

See Also

Other Govstyle feedback types: details(), gov_summary(), insert_text(), label_hint(), noti_banner(), tag_Input(), value_box(), warning_text()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(size = "full",
    shinyGovstyle::panel_output(
      inputId = "panel1",
      main_text = "Application Complete",
      sub_text = paste(
        "Thank you for submitting your application.",
        "Your reference is xvsiq"
      )
    ),
    shinyGovstyle::footer(full = TRUE)
  )
)

server <- function(input, output, session) {}
if (interactive()) shinyApp(ui = ui, server = server)

Radio Button Function

Description

This function create radio buttons

Usage

radio_button_Input(
  inputId,
  label,
  choices = NULL,
  selected = NULL,
  inline = FALSE,
  small = FALSE,
  choiceNames = NULL,
  choiceValues = NULL,
  hint_label = NULL,
  error = FALSE,
  error_message = NULL,
  custom_class = ""
)

Arguments

inputId

The input slot that will be used to access the value

label

Input label

choices

List of values to select from (if elements of the list are named then that name rather than the value is displayed to the user)

selected

The initially selected value.

inline

If you want the radio inline or not, Default is FALSE

small

If you want the smaller versions of radio buttons, Default is FALSE

choiceNames, choiceValues

Same as in shiny::checkboxGroupInput(). List of names and values, respectively, that are displayed to the user in the app and correspond to the each choice (for this reason they must have the same length). If either of these arguments is provided, then the other must be provided and choices must not be provided. The advantage of using both of these over a named list for choices is that choiceNames allows any type of UI object to be passed through (tag objects, icons, HTML code, ...), instead of just simple text

hint_label

Additional hint text you may want to display below the label. Defaults to NULL

error

Whenever you want to include error handle on the component

error_message

If you want a default error message

custom_class

If you want to add additional classes to the radio buttons

Value

radio buttons HTML shiny tag object

See Also

Other Govstyle select inputs: button_Input(), checkbox_Input(), file_Input(), select_Input()

Examples

ui <- shiny::fluidPage(
  # Required for error handling function
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", "This is a new service"
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    # Simple radio
    shinyGovstyle::radio_button_Input(
      inputId = "radio1",
      choices = c("Yes", "No", "Maybe"),
      label = "Choice option"
    ),
    # Error radio
    shinyGovstyle::radio_button_Input(
      inputId = "radio2",
      choices = c("Yes", "No", "Maybe"),
      label = "Choice option",
      hint_label = "Select the best fit",
      inline = TRUE,
      error = TRUE,
      error_message = "Select one"
    ),
    # Button to trigger error
    shinyGovstyle::button_Input(inputId = "submit", label = "Submit")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  # Trigger error on blank submit of eventId2
  observeEvent(input$submit, {
    if (is.null(input$radio2)) {
      shinyGovstyle::error_on(inputId = "radio2")
    } else {
      shinyGovstyle::error_off(
        inputId = "radio2"
      )
    }
  })
}
if (interactive()) shinyApp(ui = ui, server = server)

Run examples

Description

This function runs an example R Shiny app showcasing different parts of the package. Code for the app can be found in the inst/example_app folder in the source code.

Usage

run_example()

Details

The app uses the bslib package as is generally recommended for Shiny apps.

The app is also deployed at the following URL: https://department-for-education.shinyapps.io/shinygovstyle-example-app/

Value

runs an R Shiny app with examples in

Examples

if (interactive()) run_example()

Select Function

Description

This function inserts a select box

Usage

select_Input(inputId, label, select_text, select_value)

Arguments

inputId

Input Id for the component

label

Insert the text for the label

select_text

Add the text that will apply in the drop down as a list

select_value

Add the value that will be used for each selection

Value

a select input HTML shiny tag object

See Also

Other Govstyle select inputs: button_Input(), checkbox_Input(), file_Input(), radio_button_Input()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png",
    logo_alt_text = "Ministry of Justice logo"
  ),
  shinyGovstyle::gov_layout(
    size = "full",
    select_Input(
      inputId = "sorter",
      label = "Sort by",
      select_text = c(
        "Recently published",
        "Recently updated",
        "Most views",
        "Most comments"
      ),
      select_value = c("published", "updated", "view", "comments")
    ),
    shiny::tags$br()
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}
if (interactive()) shinyApp(ui = ui, server = server)

Service navigation

Description

Service navigation component consistent with the GDS service navigation. # nolint

Note: This component uses a hardcoded element ID for the navigation list and mobile menu toggle. Using multiple service_navigation() instances on the same page will cause ID conflicts and the mobile menu toggle may not work correctly.

Usage

service_navigation(links, service_name = NULL)

Arguments

links

A vector of actionLinks to be added to the service navigation. inputIDs are auto-generated by lowercasing the link text and replacing all non-alphanumeric characters with underscores, e.g. "Overview page" becomes overview_page. For precise control over inputIDs, supply a named vector where names are the page titles and values are the inputIDs.

service_name

An optional character string containing the service name to be displayed in the navigation bar

Value

Shiny tag object

See Also

Other Govstyle navigation: backlink_Input(), contents_link(), update_service_navigation()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header("Title", "Secondary heading"),
  shinyGovstyle::service_navigation(
     c("Summary data", "Detailed stats 1", "User guide")
  ),
  bslib::navset_hidden(
     id = "main_panels",
     bslib::nav_panel(
       "summary_data",
       shiny::tags$h2("Summary data")
     ),
     bslib::nav_panel(
       "detailed_stats_1",
       shiny::tags$h2("Detailed stats 1")
     ),
     bslib::nav_panel(
       "user_guide",
       shiny::tags$h2("User guide")
     )
   ),
   shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  observeEvent(
    input$summary_data,
    bslib::nav_select("main_panels", "summary_data")
  )
  observeEvent(
    input$detailed_stats_1,
    bslib::nav_select("main_panels", "detailed_stats_1")
  )
  observeEvent(
    input$user_guide,
    bslib::nav_select("main_panels", "user_guide")
  )
}

if (interactive()) shiny::shinyApp(ui = ui, server = server)

Skip to main content link

Description

This function generates a 'Skip to main content' link, which is typically used by keyboard users to bypass content and navigate directly to the main content of a page.

Usage

skip_to_main(id = "main")

Arguments

id

An optional parameter to specify the Id of the main content section, will be automatically preceeded by a hash '#'. Default is "main" to match the "#main" Id within gov_main().

Value

A Shiny tag representing the 'Skip to main content' link

See Also

Other Govstyle page structure: banner(), cookieBanner(), footer(), gov_layout(), header(), layouts

Examples

ui <- shiny::fluidPage(
  skip_to_main(),
  header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  gov_main_layout(
    heading_text("Example heading"),
  )
)

server <- function(input, output, session){}

if (interactive()) shinyApp(ui = ui, server = server)

Tag Function

Description

This function creates a tag.

Usage

tag_Input(inputId, text, colour = "navy")

Arguments

inputId

The Id to access the tag

text

The text in the tag

colour

The colour of the tag. Default is navy. Other options are grey, green, teal, blue, purple, magenta, red, orange and yellow

Value

a tag HTML shiny tag object

See Also

Other Govstyle feedback types: details(), gov_summary(), insert_text(), label_hint(), noti_banner(), panel_output(), value_box(), warning_text()

Examples

ui <- shiny::fluidPage(
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo="shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    shinyGovstyle::tag_Input("tag1", "Complete"),
    shinyGovstyle::tag_Input("tag2", "Incomplete", "red")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {}
if (interactive()) shinyApp(ui = ui, server = server)

Text Area Input Function

Description

This function create a text area input.

Usage

text_area_Input(
  inputId,
  label,
  hint_label = NULL,
  row_no = 5,
  error = FALSE,
  error_message = NULL,
  word_limit = NULL
)

Arguments

inputId

The input slot that will be used to access the value

label

Display label for the control, or NULL for no label

hint_label

Display hint label for the control, or NULL for no hint label

row_no

Size of the text entry box. Defaults to 5

error

Whenever to include error handling. Defaults to FALSE

error_message

Message to display on error. Defaults to NULL

word_limit

Add a word limit to the display. Defaults to NULL

Value

a text area box HTML shiny tag object

See Also

Other Govstyle text types: date_Input(), gov_list(), heading_text(), input_field(), text_Input(), word_count()

Examples

text_area_Input(
  "taId",
  "Can you provide more detail?",
  paste(
    "Do not include personal or financial information, like your",
    "National Insurance number or credit card details."
  )
)

Text Input Function

Description

This function create a text input.

Usage

text_Input(
  inputId,
  label,
  hint_label = NULL,
  type = "text",
  width = NULL,
  error = FALSE,
  error_message = NULL,
  prefix = NULL,
  suffix = NULL
)

Arguments

inputId

The input slot that will be used to access the value

label

Display label for the control, or NULL for no label

hint_label

Display hint label for the control, or NULL for no hint label

type

Type of text input to accept. Defaults to text

width

control the size of the box based on number of characters required. Options are 30, 20, 10, 5, 4, 3, 2. NULL will not limit the size

error

Whenever to include error handling. Defaults to FALSE

error_message

Message to display on error. Defaults to NULL

prefix

Add a prefix to the box. Defaults to NULL

suffix

Add a suffix to the box. Defaults to NULL

Value

a text input HTML shiny tag object

See Also

Other Govstyle text types: date_Input(), gov_list(), heading_text(), input_field(), text_area_Input(), word_count()

Examples

ui <- shiny::fluidPage(
  # Required for error handling function
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    org_name = "Example",
    service_name = "User Examples",
    logo = "shinyGovstyle/images/moj_logo.png"
  ),
  shinyGovstyle::banner(
    inputId = "banner", type = "beta", 'This is a new service'
  ),
  shinyGovstyle::gov_layout(
    size = "two-thirds",
    # Simple text box
    shinyGovstyle::text_Input(inputId = "eventId", label = "Event Name"),
    # Error text box
    shinyGovstyle::text_Input(
      inputId = "eventId2",
      label = "Event Name",
      hint_label = "This can be found on the letter",
      error = TRUE
    ),
    # Button to trigger error
    shinyGovstyle::button_Input(inputId = "submit", label = "Submit")
  ),
  shinyGovstyle::footer(full = TRUE)
)

server <- function(input, output, session) {
  # Trigger error on blank submit of eventId2
  observeEvent(input$submit, {
    if (input$eventId2 != "") {
      shinyGovstyle::error_off(inputId = "eventId2")
    } else {
      shinyGovstyle::error_on(
        inputId = "eventId2",
        error_message = "Please complete"
      )
    }
  })
}

if (interactive()) shinyApp(ui = ui, server = server)

Transport data

Description

Simple example dataset containing transport data, used to demonstrate various table styles in the example app.

Usage

transport_data

Format

A data frame with 10 rows and 5 variables:

months

The month the data belongs to

colours

The colour of the vehicle

bikes

Cost of bikes

vans

Cost of vans

buses

Cost of buses

Source

Random data generated for the shinyGovstyle package


Transport data small

Description

Smaller example dataset containing transport data, used to demonstrate various table styles in the example app.

Usage

transport_data_small

Format

A data frame with 3 rows and 3 variables:

months

The month the data belongs to

bikes

Cost of bikes

cars

Cost of cars

Source

Random data generated for the shinyGovstyle package


Update the active item in a service navigation component

Description

Sends a message to the browser to update the highlighted active item in the service navigation bar.

When you need this function: when navigation is triggered programmatically — for example, via a next / back button or a footer link that points to a main page. In those cases the nav link itself is not clicked, so the JavaScript binding does not fire and the active state does not update automatically. Call update_service_navigation() alongside your tab-switching call to keep them in sync.

When you don't need this function: when the user clicks a service navigation link directly. The JavaScript binding updates the active state automatically, so you only need to switch the tab panel in your observeEvent().

Usage

update_service_navigation(session, inputId)

Arguments

session

The Shiny session object

inputId

The inputId of the service navigation link to set as active

Value

NULL, called for side effects

See Also

Other Govstyle navigation: backlink_Input(), contents_link(), service_navigation()

Examples

# Nav link clicked — JS handles active state, just switch the panel.
# Works the same whether you use shiny or bslib tab panels.
if (interactive()) {
  server <- function(input, output, session) {
    # shiny tabsetPanel
    shiny::observeEvent(input$page_two, {
      shiny::updateTabsetPanel(session, "tabs", selected = "page_two")
    })

    # bslib navset
    shiny::observeEvent(input$page_two, {
      bslib::nav_select("tabs", "page_two")
    })
  }
}

# Programmatic navigation (e.g. a next / back button) — the nav link is not
# clicked, so you must also call update_service_navigation() explicitly.
if (interactive()) {
  server <- function(input, output, session) {
    # shiny tabsetPanel
    shiny::observeEvent(input$next_btn, {
      shiny::updateTabsetPanel(session, "tabs", selected = "page_two")
      shinyGovstyle::update_service_navigation(session, "page_two")
    })

    # bslib navset
    shiny::observeEvent(input$next_btn, {
      bslib::nav_select("tabs", "page_two")
      shinyGovstyle::update_service_navigation(session, "page_two")
    })
  }
}

Create a value text box with optional description and colour

Description

This function generates a value text box with an optional description and customisable colour.

Usage

value_box(value = "your value goes here", text = NA, colour = "blue")

Arguments

value

Character. The primary value to display in the value box. Defaults to "your value goes here"

text

Character or NA. An optional description to appear below the value. If not provided (default is NA), the description will not be displayed

colour

Character. A colour to apply to the value box. Defaults to "blue". Choose from the following: "grey", "purple", "teal", "blue", "yellow", "orange", "red", "magenta", or "green"

Details

The text box can be used in Shiny applications to display highlighted information, such as statistics or key metrics.

Value

A Shiny div tag representing the value box, styled according to the specified parameters

See Also

Other Govstyle feedback types: details(), gov_summary(), insert_text(), label_hint(), noti_banner(), panel_output(), tag_Input(), warning_text()

Examples

value_box(
  value = "1,000,000",
  text = "This is the latest value for the selected inputs.",
  colour = "purple"
)

Warning Text Function

Description

This function create warning text.

Usage

warning_text(inputId, text)

Arguments

inputId

The input slot that will be used to access the value

text

Text that goes in the main. Accepts a plain character string, or shiny tag objects such as shiny::tags$b("Bold") or a shiny::tagList().

Value

a warning box HTML shiny tag object

See Also

Other Govstyle feedback types: details(), gov_summary(), insert_text(), label_hint(), noti_banner(), panel_output(), tag_Input(), value_box()

Examples

shinyGovstyle::warning_text(
  inputId = "warn1",
  text = "You can be fined up to £5,000 if you do not register."
)

Word Count Function

Description

This function create tracks the word count and should be used with the text area function.

Usage

word_count(inputId, input, word_limit = NULL)

Arguments

inputId

The input slot of the text area that you want to affect

input

The text input that is associated with the box

word_limit

Change the word limit if needed. Default will keep as what was used in text area component

Value

no value returned. Updates the word count in a shiny app

See Also

Other Govstyle text types: date_Input(), gov_list(), heading_text(), input_field(), text_Input(), text_area_Input()

Examples

ui <- shiny::fluidPage(
  shinyjs::useShinyjs(),
  shinyGovstyle::header(
    "Justice", "", logo = "shinyGovstyle/images/moj_logo.png"
  ),
  gov_layout(
    size = "full",
    text_area_Input(
      inputId = "text_area",
      label = "Can you provide more detail?",
      hint_label = paste(
        "Do not include personal or financial information,",
        "like your National Insurance number or credit card details."
      ),
      word_limit = 300
    )
  ),
  footer(TRUE)
)

server <- function(input, output, session) {
  shiny::observeEvent(input$text_area,
    word_count(
      inputId = "text_area",
      input = input$text_area
    )
  )
}
if (interactive()) shinyApp(ui = ui, server = server)