Title: | Custom Gov Style Inputs for Shiny |
---|---|
Description: | Collection of 'shiny' application styling that are the based on the GOV.UK Design System. See <https://design-system.service.gov.uk/components/> for details. |
Authors: | Ross Wyatt [aut, cre], Cameron Race [ctb], Sarah Wong [ctb], Richard Bielby [ctb], Charlotte Foster [ctb], Jeni Martin [ctb] |
Maintainer: | Ross Wyatt <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.0.9000 |
Built: | 2024-12-12 20:26:09 UTC |
Source: | https://github.com/dfe-analytical-services/shinygovstyle |
This function inserts a accordion
accordion(inputId, titles, descriptions)
accordion(inputId, titles, descriptions)
inputId |
Input id for the accordion |
titles |
Add the titles for the accordion |
descriptions |
Add the main text for the accordion |
an accordion html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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", 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) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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", 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) {} shinyApp(ui = ui, server = server) }
This function adds a back link to the page
backlink_Input(inputId, label = "Back")
backlink_Input(inputId, label = "Back")
inputId |
The input slot that will be used to access the value. |
label |
The link text for the backlink, default is "Back" |
a backlink html shiny object
if (interactive()) { ui <- fluidPage( header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shiny::navlistPanel( "", id="nav", widths = c(2, 10), well = FALSE, #Create first panel shiny::tabPanel( "Select Types", value = "panel1", gov_layout(size = "two-thirds", backlink_Input("link1"), shiny::tags$br(), shiny::tags$br() )), shiny::tabPanel( "Tab2", value = "panel2")), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) { #Slightly confused in that it goes forward rather than back, but shows how #to use observeEvent(input$link1,{ updateTabsetPanel(session, "nav", selected = "panel2") }) } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shiny::navlistPanel( "", id="nav", widths = c(2, 10), well = FALSE, #Create first panel shiny::tabPanel( "Select Types", value = "panel1", gov_layout(size = "two-thirds", backlink_Input("link1"), shiny::tags$br(), shiny::tags$br() )), shiny::tabPanel( "Tab2", value = "panel2")), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) { #Slightly confused in that it goes forward rather than back, but shows how #to use observeEvent(input$link1,{ updateTabsetPanel(session, "nav", selected = "panel2") }) } shinyApp(ui = ui, server = server) }
A single column data frame, listing out known examples of bad link text that check for in the 'external_link()' function.
bad_link_text
bad_link_text
## 'bad_link_text' A data frame with 53 rows and 1 columns:
Lower cased examples of non-descriptive link text
We've started curating this list so we can create automated checks to help all link text to be as descriptive as possible in line with [WCAG 2.2 success criteria 2.4.4: Link Purpose (In Context)]( https://www.w3.org/WAI/WCAG22/Understanding/link-purpose-in-context).
Curated by [email protected]
This function create a detail component that you can click for further details.
banner(inputId, type, label)
banner(inputId, type, label)
inputId |
The input slot that will be used to access the value. |
type |
Main type of label e.g. alpha or beta. Can be any word. |
label |
test to display. |
a banner html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::banner( inputId = "banner", type = "Beta", 'This is a new service') ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::banner( inputId = "banner", type = "Beta", 'This is a new service') ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function create a gov style button
button_Input(inputId, label, type = "default")
button_Input(inputId, label, type = "default")
inputId |
The input slot that will be used to access the value. |
label |
Display label for the control, or |
type |
The type of button. Options are default, start, secondary and warning. Defaults to default. |
a html button shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
This function inserts a checkbox group
checkbox_Input( inputId, cb_labels, checkboxIds, label, hint_label = NULL, small = FALSE, error = FALSE, error_message = NULL )
checkbox_Input( inputId, cb_labels, checkboxIds, label, hint_label = NULL, small = FALSE, error = FALSE, error_message = NULL )
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 |
error |
Whenever you want to include error handle on the component. |
error_message |
If you want a default error message. |
a checkbox html shiny object
if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
This function creates an action link to nav between tabs and optionally link to subcontents headers.
contents_link(link_text, input_id, subcontents_text_list, subcontents_id_list)
contents_link(link_text, input_id, subcontents_text_list, subcontents_id_list)
link_text |
vector of link text for contents |
input_id |
contents button id |
subcontents_text_list |
vector of link text for subcontents |
subcontents_id_list |
vector of link ids for subcontents. if missing automatically matches to id in shinygovstyle::heading_text |
an action button html shiny object
if (interactive()) { ui <- shiny::fluidPage( title="ShinyGovstyle", cookieBanner("Run Example"), header("MOJ", "ShinyGovstyle Example", logo="shinyGovstyle/images/moj_logo-1.png", logo_width = 66), banner( "banner", "Beta", 'This is a new service \u002D your <a class="govuk-link" href="#"> 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( width = 3, id = "nav", # DO NOT REMOVE ID # Contents box shiny::tags$div( id = "govuk-contents-box", #DO NOT REMOVE ID class = "govuk-contents-box", #DO NOT REMOVE CLASS shiny::tags$h2("Contents"), # Text types tab contents_link( "Text Types", "text_types_button", subcontents_text_list = c("date_Input", "text_Input", "text_area_Input", "button_Input"), subcontents_id_list = c(NA, NA, NA, "button_input_text_types") ), # Tables tabs and accordions tab contents_link( "Tables, tabs and accordions", "tables_tabs_and_accordions_button", subcontents_text_list = c("govTable", "govTabs", "accordions", "button_Input"), subcontents_id_list = c(NA, NA, NA, "button_input_tables_tabs_accordions") ), contents_link( "Cookies", "cookies_button"), ) ), shiny::column( width = 9, id = "main_col", # DO NOT REMOVE ID #Set up a nav panel so everything not on single page shiny::tabsetPanel( type = "hidden", id = "tab-container", # DO NOT REMOVE ID shiny::tabPanel( "Text Types", value = "text_types", gov_layout( size = "two-thirds", backlink_Input("back1"), heading_text("Page 2", size = "l"), label_hint("label2", "These are some examples of the types of user text inputs that you can use"), heading_text("date_Input", size = "s"), date_Input( inputId = "date1", label = "What is your date of birth?", hint_label = "For example, 31 3 1980"), heading_text("text_Input", size = "s"), text_Input(inputId = "txt1", label = "Event name"), heading_text("text_area_Input", size = "s"), text_area_Input( inputId = "text_area1", label = "Can you provide more detail?", hint_label = "Do not include personal or financial information, like your National Insurance number or credit card details."), text_area_Input( inputId = "text_area2", label = "How are you today?", hint_label = "Leave blank to trigger error", error = T, error_message = "Please do not leave blank", 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") ) ), shiny::tabPanel( "Tables, tabs and accordions", value = "tables_tabs_and_accordions", gov_layout( size = "two-thirds", backlink_Input("back2"), heading_text("Page 3", size = "l"), label_hint("label3", "These are some examples of using tabs and tables"), heading_text("govTable", size = "s"), heading_text("govTabs", size = "s"), heading_text("accordions", size = "s"), shinyGovstyle:: 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." )), heading_text( "button_Input", size = "s", id = "button_input_tables_tabs_accordions"), button_Input("btn4", "Go to next page"), ) ), #####################Create cookie panel################################ shiny::tabPanel( "Cookies", value = "panel-cookies", gov_layout( size = "two-thirds", heading_text("Cookie page", size = "l"), label_hint("label-cookies", "This an example cookie page that could be expanded") ) ))) ), #end of gov row footer(TRUE) ) #end of fluid page server <- function(input, output, session) { # Tab nav shiny::observeEvent(input$back2, { shiny::updateTabsetPanel(session, "tab-container", selected = "text_types") }) shiny::observeEvent(input$tables_tabs_and_accordions_button, { shiny::updateTabsetPanel(session, "tab-container", selected = "tables_tabs_and_accordions") }) shiny::observeEvent(input$cookies_button, { shiny::updateTabsetPanel(session, "tab-container", selected = "panel-cookies") }) } shiny::shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- shiny::fluidPage( title="ShinyGovstyle", cookieBanner("Run Example"), header("MOJ", "ShinyGovstyle Example", logo="shinyGovstyle/images/moj_logo-1.png", logo_width = 66), banner( "banner", "Beta", 'This is a new service \u002D your <a class="govuk-link" href="#"> 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( width = 3, id = "nav", # DO NOT REMOVE ID # Contents box shiny::tags$div( id = "govuk-contents-box", #DO NOT REMOVE ID class = "govuk-contents-box", #DO NOT REMOVE CLASS shiny::tags$h2("Contents"), # Text types tab contents_link( "Text Types", "text_types_button", subcontents_text_list = c("date_Input", "text_Input", "text_area_Input", "button_Input"), subcontents_id_list = c(NA, NA, NA, "button_input_text_types") ), # Tables tabs and accordions tab contents_link( "Tables, tabs and accordions", "tables_tabs_and_accordions_button", subcontents_text_list = c("govTable", "govTabs", "accordions", "button_Input"), subcontents_id_list = c(NA, NA, NA, "button_input_tables_tabs_accordions") ), contents_link( "Cookies", "cookies_button"), ) ), shiny::column( width = 9, id = "main_col", # DO NOT REMOVE ID #Set up a nav panel so everything not on single page shiny::tabsetPanel( type = "hidden", id = "tab-container", # DO NOT REMOVE ID shiny::tabPanel( "Text Types", value = "text_types", gov_layout( size = "two-thirds", backlink_Input("back1"), heading_text("Page 2", size = "l"), label_hint("label2", "These are some examples of the types of user text inputs that you can use"), heading_text("date_Input", size = "s"), date_Input( inputId = "date1", label = "What is your date of birth?", hint_label = "For example, 31 3 1980"), heading_text("text_Input", size = "s"), text_Input(inputId = "txt1", label = "Event name"), heading_text("text_area_Input", size = "s"), text_area_Input( inputId = "text_area1", label = "Can you provide more detail?", hint_label = "Do not include personal or financial information, like your National Insurance number or credit card details."), text_area_Input( inputId = "text_area2", label = "How are you today?", hint_label = "Leave blank to trigger error", error = T, error_message = "Please do not leave blank", 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") ) ), shiny::tabPanel( "Tables, tabs and accordions", value = "tables_tabs_and_accordions", gov_layout( size = "two-thirds", backlink_Input("back2"), heading_text("Page 3", size = "l"), label_hint("label3", "These are some examples of using tabs and tables"), heading_text("govTable", size = "s"), heading_text("govTabs", size = "s"), heading_text("accordions", size = "s"), shinyGovstyle:: 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." )), heading_text( "button_Input", size = "s", id = "button_input_tables_tabs_accordions"), button_Input("btn4", "Go to next page"), ) ), #####################Create cookie panel################################ shiny::tabPanel( "Cookies", value = "panel-cookies", gov_layout( size = "two-thirds", heading_text("Cookie page", size = "l"), label_hint("label-cookies", "This an example cookie page that could be expanded") ) ))) ), #end of gov row footer(TRUE) ) #end of fluid page server <- function(input, output, session) { # Tab nav shiny::observeEvent(input$back2, { shiny::updateTabsetPanel(session, "tab-container", selected = "text_types") }) shiny::observeEvent(input$tables_tabs_and_accordions_button, { shiny::updateTabsetPanel(session, "tab-container", selected = "tables_tabs_and_accordions") }) shiny::observeEvent(input$cookies_button, { shiny::updateTabsetPanel(session, "tab-container", selected = "panel-cookies") }) } shiny::shinyApp(ui = ui, server = server) }
This function creates a cookie banner. You need to have shinyjs::useShinyjs() enabled to work. All the ids are pre set. See example for how to structure.
cookieBanner(service_name)
cookieBanner(service_name)
service_name |
Name for this service to add to banner |
a cookie banner html shiny object.
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) { #Need these 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 }) } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) { #Need these 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 }) } shinyApp(ui = ui, server = server) }
This function create a date input that follows GDS component
date_Input( inputId, label, hint_label = NULL, error = FALSE, error_message = NULL, day = NULL, month = NULL, year = NULL )
date_Input( inputId, label, hint_label = NULL, error = FALSE, error_message = NULL, day = NULL, month = NULL, year = NULL )
inputId |
The input slot that will be used to access the value. |
label |
Display label for the control, or |
hint_label |
Display hint label for the control, or |
error |
Whenever to include error components.Defaults to |
error_message |
Error handling message? Defaults to |
day |
Select a default day on start up. Defaults to |
month |
Select a default month on start up. Defaults to |
year |
Select a default year on start up. Defaults to |
a data input html shiny object
if (interactive()) { ui <- fluidPage( # Required for error handling function. shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( # Required for error handling function. shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
This function create a detail component that you can click for further details.
details(inputId, label, help_text)
details(inputId, label, help_text)
inputId |
The input slot that will be used to access the value. |
label |
Main label text |
help_text |
Additional help information in the component. |
a details box html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
This function turns off the the error o the component, once issues have been sorted.
error_off(inputId)
error_off(inputId)
inputId |
The inputId to turn error handling iff for on for. |
no return value. This toggles off error css
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } # Run the application shinyApp(ui = ui, server = server) }
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } # Run the application shinyApp(ui = ui, server = server) }
This function turns on the the error o the component. Can be used to validate inputs.
error_on(inputId, error_message = NULL)
error_on(inputId, error_message = NULL)
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 |
no return value. This toggles on error css
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } # Run the application shinyApp(ui = ui, server = server) }
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } # Run the application shinyApp(ui = ui, server = server) }
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/
error_summary(inputId, error_title, error_list)
error_summary(inputId, error_title, error_list)
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. |
an error_summary html shiny object
if (interactive()) { ui <- fluidPage( shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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 ) } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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 ) } shinyApp(ui = ui, server = server) }
This function changes the text that displays in the error summary box. Requires shinyjs::useShinyjs() to work.
error_summary_update(inputId, error_list)
error_summary_update(inputId, error_list)
inputId |
The inputid of the error summary you want to update |
error_list |
An updated list of text values to be displayed in the error body. |
an update error summary box
if (interactive()) { ui <- fluidPage( shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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 ) } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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 ) } shinyApp(ui = ui, server = server) }
It is commonplace for external links to open in a new tab, and when we do this we should be careful...
This function automatically adds the following to your link: * 'target="_blank"' to open in new tab * 'rel="noopener noreferrer"' to prevent [reverse tabnabbing]( https://owasp.org/www-community/attacks/Reverse_Tabnabbing)
By default this function also adds "(opens in new tab)" to your link text to warn users of the behaviour.
This also adds "This link opens in a new tab" as a visually hidden span element within the HTML outputted to warn non-visual users of the behaviour.
The function will error if you end with a full stop, give a warning for particularly short link text and will automatically trim any leading or trailing white space inputted into link_text.
If you are displaying lots of links together and want to save space by avoiding repeating (opens in new tab), then you can set add_warning = FALSE and add a line of text above all of the links saying something like 'The following links open in a new tab'.
Related links and guidance:
* [Government digital services guidelines on the use of links]( https://design-system.service.gov.uk/styles/links/)
* [Anchor tag HTML element and its properties]( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a)
* [WCAG 2.2 success criteria 2.4.4: Link Purpose (In Context)]( https://www.w3.org/WAI/WCAG22/Understanding/link-purpose-in-context)
* [Web Accessibility standards link text behaviour]( https://www.w3.org/TR/WCAG20-TECHS/G200.html)
external_link(href, link_text, add_warning = TRUE)
external_link(href, link_text, add_warning = TRUE)
href |
URL that you want the link to point to |
link_text |
Text that will appear describing your link, must be descriptive of the page you are linking to. 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. |
add_warning |
Boolean for adding "(opens in new tab)" at the end of the link text to warn users of the behaviour. Be careful and consider accessibility before removing the visual warning. |
Intentionally basic wrapper for HTML anchor elements making it easier to
create safe external links with standard and accessible behaviour. For more
information on how the tag is generated, see tags
.
shiny.tag object
external_link("https://shiny.posit.co/", "R Shiny") external_link( "https://shiny.posit.co/", "R Shiny", add_warning = FALSE ) # This will trim and show as 'R Shiny' external_link("https://shiny.posit.co/", " R Shiny") # Example of within text shiny::tags$p( "Oi, ", external_link("https://shiny.posit.co/", "R Shiny"), " is great." ) # Example of multiple links together shiny::tags$h2("Related resources") shiny::tags$p("The following links open in a new tab.") shiny::tags$ul( shiny::tags$li( external_link( "https://shiny.posit.co/", "R Shiny documentation", add_warning = FALSE ) ), shiny::tags$li( external_link( "https://www.python.org/", "Python documentation", add_warning = FALSE ) ), shiny::tags$li( external_link( "https://nextjs.org/", "Next.js documentation", add_warning = FALSE ) ) )
external_link("https://shiny.posit.co/", "R Shiny") external_link( "https://shiny.posit.co/", "R Shiny", add_warning = FALSE ) # This will trim and show as 'R Shiny' external_link("https://shiny.posit.co/", " R Shiny") # Example of within text shiny::tags$p( "Oi, ", external_link("https://shiny.posit.co/", "R Shiny"), " is great." ) # Example of multiple links together shiny::tags$h2("Related resources") shiny::tags$p("The following links open in a new tab.") shiny::tags$ul( shiny::tags$li( external_link( "https://shiny.posit.co/", "R Shiny documentation", add_warning = FALSE ) ), shiny::tags$li( external_link( "https://www.python.org/", "Python documentation", add_warning = FALSE ) ), shiny::tags$li( external_link( "https://nextjs.org/", "Next.js documentation", add_warning = FALSE ) ) )
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. It doesn't look like the www.gov.uk/ style one, although this www.gov.uk/ doesn't seem to have a settle style as, for example it changes between Firefox and Chrome
file_Input( inputId, label, multiple = FALSE, accept = NULL, width = NULL, buttonLabel = "Choose file", placeholder = "No file chosen", error = FALSE, error_message = NULL )
file_Input( inputId, label, multiple = FALSE, accept = NULL, width = NULL, buttonLabel = "Choose file", placeholder = "No file chosen", error = FALSE, error_message = NULL )
inputId |
The input slot that will be used to access the value. |
label |
Display label for the control, or |
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. |
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 |
a file input html shiny object
if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
This function adds rge nta fonts to the app. See https://design-system.service.gov.uk/styles/typography/ for when they are allowed.
font()
font()
no value returned. This loads the font css file
if (interactive()) { ui <- fluidPage( font(), shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png") ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( font(), shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png") ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
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.
gov_layout(..., inputID = "main", size = "full")
gov_layout(..., inputID = "main", size = "full")
... |
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" |
a html shiny layout div
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "full", shinyGovstyle::panel_output( inputId = "panel1", main_text = "Application Complete", sub_text = "Thank you for submitting your application. Your reference is xvsiq") ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "full", shinyGovstyle::panel_output( inputId = "panel1", main_text = "Application Complete", sub_text = "Thank you for submitting your application. Your reference is xvsiq") ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function creates a tabs based table. It requires a single dataframe with a grouping variable
gov_summary(inputId, headers, info, action = FALSE, border = TRUE)
gov_summary(inputId, headers, info, action = FALSE, border = TRUE)
inputId |
The id to access the summary list |
headers |
input for the row headers value |
info |
summary information values for the table |
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 |
border |
set if the table should have borders. Default set
to |
a summary list table html shiny object.
if (interactive()) { # 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 <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
if (interactive()) { # 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 <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
This function inserts a gov styled table. Format is with header looking rows and columns
govTable( inputId, df, caption, caption_size = "l", num_col = NULL, width_overwrite = NULL )
govTable( inputId, df, caption, caption_size = "l", num_col = NULL, width_overwrite = NULL )
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.
Options are three-quarters, two-thirds, one-half, one-third, one-quarter.
Default is |
an table html shiny object
if (interactive()) { Months <- c("January", "February", "March") Bikes <- c("£85", "£75", "£165") Cars <- c("£95", "£55", "£125") example_data <- data.frame(Months, Bikes, Cars) ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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::govTable( "tab1", example_data, "Test", "l", num_col = c(2,3), width_overwrite = c("one-half", "one-quarter", "one-quarter")) ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { Months <- c("January", "February", "March") Bikes <- c("£85", "£75", "£165") Cars <- c("£95", "£55", "£125") example_data <- data.frame(Months, Bikes, Cars) ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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::govTable( "tab1", example_data, "Test", "l", num_col = c(2,3), width_overwrite = c("one-half", "one-quarter", "one-quarter")) ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function creates a tabs based table. It requires a single dataframe with a grouping variable
govTabs(inputId, df, group_col)
govTabs(inputId, df, group_col)
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 |
a tab table html shiny object.
if (interactive()) { # Create an example dataset tabs <- c(rep("Past Day", 3), rep("Past Week", 3), rep("Past Month", 3), rep("Past Year", 3)) Case_manager <- rep(c("David Francis", "Paul Farmer", "Rita Patel"),4) Cases_open <- c(3, 1, 2, 24, 16, 24, 98, 122, 126, 1380, 1129, 1539) Cases_closed <- c(0, 0, 0, 18, 20, 27, 95, 131, 142, 1472, 1083, 1265) data <- data.frame(tabs, Case_manager, Cases_open, Cases_closed) ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "two-thirds", shinyGovstyle::govTabs(data, "tabs")), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { # Create an example dataset tabs <- c(rep("Past Day", 3), rep("Past Week", 3), rep("Past Month", 3), rep("Past Year", 3)) Case_manager <- rep(c("David Francis", "Paul Farmer", "Rita Patel"),4) Cases_open <- c(3, 1, 2, 24, 16, 24, 98, 122, 126, 1380, 1129, 1539) Cases_closed <- c(0, 0, 0, 18, 20, 27, 95, 131, 142, 1472, 1083, 1265) data <- data.frame(tabs, Case_manager, Cases_open, Cases_closed) ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "two-thirds", shinyGovstyle::govTabs(data, "tabs")), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function create a header banner. For use at top of the screen
header( main_text, secondary_text, logo = NULL, main_link = "#", secondary_link = "#", logo_width = 36, logo_height = 32 )
header( main_text, secondary_text, logo = NULL, main_link = "#", secondary_link = "#", logo_width = 36, logo_height = 32 )
main_text |
Main text that goes in the header |
secondary_text |
Secondary header to supplement the main text |
logo |
Add a link to a logo which will apply in the header. Use crown to use the crown svg version on gov uk. |
main_link |
Add a link for clicking on main text |
secondary_link |
Add a link for clicking on secondary header. |
logo_width |
Change the logo size width css to improve fit |
logo_height |
Change the logo size height css to improve fit |
a header html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png") ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png") ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function create a heading text
heading_text(text_input, size = "xl", id)
heading_text(text_input, size = "xl", id)
text_input |
Text to display |
size |
Text size using xl, l, m, s. Defaults to xl. |
id |
Custom header id |
a heading text html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "two-thirds", shinyGovstyle::heading_text("This is great text", "m") ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "two-thirds", shinyGovstyle::heading_text("This is great text", "m") ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function inserts number of text inputs. Useful for addresses.
input_field( legend, labels, inputIds, widths = NULL, types = "text", error = FALSE, error_message = NULL )
input_field( legend, labels, inputIds, widths = NULL, types = "text", error = FALSE, error_message = NULL )
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 |
a input field of html as a shiny object
if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
This function loads the insert text component to display additional information in a special format.
insert_text(inputId, text)
insert_text(inputId, text)
inputId |
The input slot that will be used to access the value. |
text |
Text that you want to display on the insert |
a insert text html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "two-thirds", shinyGovstyle::insert_text( inputId = "note", text = "It can take up to 8 weeks to register a lasting power of attorney if there are no mistakes in the application." ) ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "two-thirds", shinyGovstyle::insert_text( inputId = "note", text = "It can take up to 8 weeks to register a lasting power of attorney if there are no mistakes in the application." ) ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function inserts a label and optional hint
label_hint(inputId, label, hint_input = NULL)
label_hint(inputId, label, hint_input = NULL)
inputId |
The input slot that will be used to access the value. |
label |
Display label for the control, or |
hint_input |
Display hint label for the control, or |
a label hint html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
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.
gov_main_layout(..., inputID = "main") gov_row(...) gov_box(..., size = "full") gov_text(...)
gov_main_layout(..., inputID = "main") gov_row(...) gov_box(..., size = "full") gov_text(...)
... |
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" |
a html shiny layout div
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
This function create a notification banner
noti_banner( inputId, title_txt = "Important", body_txt = NULL, type = "standard" )
noti_banner( inputId, title_txt = "Important", body_txt = NULL, type = "standard" )
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 |
type |
The type of banner. Options are standard and success. Standard is default |
a notification html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
This function inserts a panel. Normally used for confirmation screens
panel_output(inputId, main_text, sub_text)
panel_output(inputId, main_text, sub_text)
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 |
a panel html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "full", shinyGovstyle::panel_output( inputId = "panel1", main_text = "Application Complete", sub_text = "Thank you for submitting your application. Your reference is xvsiq") ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "full", shinyGovstyle::panel_output( inputId = "panel1", main_text = "Application Complete", sub_text = "Thank you for submitting your application. Your reference is xvsiq") ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function create radio buttons
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 = "" )
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 = "" )
inputId |
The |
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
|
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 |
radio buttons html shiny object
if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } shinyApp(ui = ui, server = server) }
This function runs a shiny example using different parts of the package
run_example()
run_example()
a shiny app with examples in
if (interactive()) { run_example() }
if (interactive()) { run_example() }
This function inserts a select box
select_Input(inputId, label, select_text, select_value)
select_Input(inputId, label, select_text, select_value)
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. |
a select input html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), 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")), tags$br() ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), 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")), tags$br() ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function generates an accessible 'Skip to main content' link, which is typically used by keyboard-only users to bypass content and navigate directly to the main content of a page. Important: your main column will need an id of "main_col" for this to work
skip_to_main()
skip_to_main()
a skip button that skips to section with id of "main_col"
if (interactive()) { ui <- fluidPage( cookieBanner("Run Example"), skip_to_main(), shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png" ), shinyjs::useShinyjs(), # shinyjs is needed to manage visibility of elements gov_row( shiny::column( width = 3, id = "nav", # Contents box shiny::tags$div( id = "govuk-contents-box", #DO NOT REMOVE ID class = "govuk-contents-box", #DO NOT REMOVE CLASS shiny::tags$h2("Contents"), p("Your contents links go here"), ) ), shiny::column( width = 9, id = "main_col", shiny::tabsetPanel( type = "hidden", id = "tab-container", # DO NOT REMOVE ID shiny::tabPanel( "Your main content", value = "your_main_content", gov_layout( size = "two-thirds", heading_text("Your main content", size = "l"), heading_text("accordions", size = "s"), shinyGovstyle:: 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." )), ) ) ) ) ) ) server <- function(input, output, session){ } shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( cookieBanner("Run Example"), skip_to_main(), shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png" ), shinyjs::useShinyjs(), # shinyjs is needed to manage visibility of elements gov_row( shiny::column( width = 3, id = "nav", # Contents box shiny::tags$div( id = "govuk-contents-box", #DO NOT REMOVE ID class = "govuk-contents-box", #DO NOT REMOVE CLASS shiny::tags$h2("Contents"), p("Your contents links go here"), ) ), shiny::column( width = 9, id = "main_col", shiny::tabsetPanel( type = "hidden", id = "tab-container", # DO NOT REMOVE ID shiny::tabPanel( "Your main content", value = "your_main_content", gov_layout( size = "two-thirds", heading_text("Your main content", size = "l"), heading_text("accordions", size = "s"), shinyGovstyle:: 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." )), ) ) ) ) ) ) server <- function(input, output, session){ } shinyApp(ui = ui, server = server) }
This function creates a tag
tag_Input(inputId, text, colour = "navy")
tag_Input(inputId, text, colour = "navy")
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, turquoise, blue, purple, pink, red, orange and yellow |
a tag html shiny object.
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "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) {} shinyApp(ui = ui, server = server) }
This function create a text area input
text_area_Input( inputId, label, hint_label = NULL, row_no = 5, error = FALSE, error_message = NULL, word_limit = NULL )
text_area_Input( inputId, label, hint_label = NULL, row_no = 5, error = FALSE, error_message = NULL, word_limit = NULL )
inputId |
The input slot that will be used to access the value. |
label |
Display label for the control, or |
hint_label |
Display hint label for the control, or |
row_no |
Size of the text entry box. Defaults to 5. |
error |
Whenever to icnlud error handling Defaults to |
error_message |
Message to display on error. Defaults to |
word_limit |
Add a word limit to the display. Defaults to |
a text area box html shiny object
text_area_Input("taId", "Can you provide more detail?", "Do not include personal or financial information, like your National Insurance number or credit card details.")
text_area_Input("taId", "Can you provide more detail?", "Do not include personal or financial information, like your National Insurance number or credit card details.")
This function create a text area input
text_Input( inputId, label, hint_label = NULL, type = "text", width = NULL, error = FALSE, error_message = NULL, prefix = NULL, suffix = NULL )
text_Input( inputId, label, hint_label = NULL, type = "text", width = NULL, error = FALSE, error_message = NULL, prefix = NULL, suffix = NULL )
inputId |
The input slot that will be used to access the value. |
label |
Display label for the control, or |
hint_label |
Display hint label for the control, or |
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 |
a text input html shiny object
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } # Run the application shinyApp(ui = ui, server = server) }
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( # Required for error handling function shinyjs::useShinyjs(), shinyGovstyle::header( main_text = "Example", secondary_text = "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") } }) } # Run the application shinyApp(ui = ui, server = server) }
This function generates a value text box with an optional description and customisable colour. The text box can be used in Shiny applications to display highlighted information, such as statistics or key metrics.
value_box(inputId, value = "your value goes here", text = NA, colour = "blue")
value_box(inputId, value = "your value goes here", text = NA, colour = "blue")
inputId |
Character. A unique identifier for the value box element. |
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", "turquoise", "blue", "light-blue", "yellow", "orange", "red", "pink", or "green". |
A Shiny 'div' tag representing the value box, styled according to the specified parameters.
if (interactive()) { ui <- fluidPage( value_text( inputId = "value1", value = "1,000,000", text = "This is the latest value for the selected inputs.", colour = "purple" ) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( value_text( inputId = "value1", value = "1,000,000", text = "This is the latest value for the selected inputs.", colour = "purple" ) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function create warning text
warning_text(inputId, text)
warning_text(inputId, text)
inputId |
The input slot that will be used to access the value. |
text |
Text that goes in the main |
a warning box html shiny object
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "two-thirds", shinyGovstyle::warning_text( inputId = "warn1", text = "You can be fined up to £5,000 if you do not register.") ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
if (interactive()) { ui <- fluidPage( shinyGovstyle::header( main_text = "Example", secondary_text = "User Examples", logo="shinyGovstyle/images/moj_logo.png"), shinyGovstyle::gov_layout(size = "two-thirds", shinyGovstyle::warning_text( inputId = "warn1", text = "You can be fined up to £5,000 if you do not register.") ), shinyGovstyle::footer(full = TRUE) ) server <- function(input, output, session) {} shinyApp(ui = ui, server = server) }
This function create tracks the word count and should be used with the text area function
word_count(inputId, input, word_limit = NULL)
word_count(inputId, input, word_limit = NULL)
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 |
no value returned. Updates the word count in a shiny app
if (interactive()) { 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 = "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 ) ) } shinyApp(ui = ui, server = server) }
if (interactive()) { 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 = "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 ) ) } shinyApp(ui = ui, server = server) }