This function turns on the error for the component. Can be used to validate inputs.
Arguments
- inputId
The id assigned to the component's root element. For Shiny input components this is also the name used to access the value via
input$<inputId>.- error_message
if you want to add an additional error message Defaults to NULL, showing the original designed error message. Plain character strings are escaped and render as literal text; pass a
shinytag,shiny::tagList(), orshiny::HTML()to render markup.
See also
Other Govstyle errors:
error_off(),
error_summary(),
error_summary_update()
Examples
ui <- shinyGovstyle::gov_page(
# 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)
