The same chart rendered with ggplot defaults versus the package’s accessible theme, palette, and alt text. Toggle WCAG level to see contrast and font thresholds shift; the audit table reports per-criterion status for each version.
#| standalone: true
#| viewerHeight: 720
library(shiny)
library(bslib)
library(ggplot2)
library(DT)
library(a11yviz)
dt_options <- list(
dom = "Bfrtip",
buttons = c("copy", "csv", "excel", "pdf"),
pageLength = 10,
scrollX = TRUE,
autoWidth = TRUE
)
ui <- page_sidebar(
sidebar = sidebar(width = 240,
radioButtons("level", "WCAG level:",
choices = c("AA", "AAA"), selected = "AA", inline = TRUE)
),
navset_card_underline(
nav_panel("Baseline",
plotOutput("plot_before", height = "320px"),
tags$h3("Audit", class = "h6 mt-3"),
DT::dataTableOutput("audit_before")
),
nav_panel("Improved",
plotOutput("plot_after", height = "320px"),
tags$h3("Audit", class = "h6 mt-3"),
DT::dataTableOutput("audit_after")
)
)
)
server <- function(input, output) {
base_plot <- reactive({
ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
geom_point() +
labs(title = "Iris (default ggplot)")
})
improved_plot <- reactive({
p <- ggplot(iris, aes(Sepal.Width, Sepal.Length,
color = Species, shape = Species)) +
geom_point() +
theme_a11y(level = input$level) +
scale_color_a11y(level = input$level) +
labs(title = "Iris (theme_a11y + scale_color_a11y)")
a11y_alt_text(p, "Iris sepal length vs sepal width by species, AA accessible.")
})
output$plot_before <- renderPlot(base_plot())
output$plot_after <- renderPlot(improved_plot())
output$audit_before <- DT::renderDT(
DT::datatable(a11y_audit(base_plot(), level = input$level),
extensions = "Buttons", options = dt_options,
class = "compact stripe hover", rownames = FALSE)
)
output$audit_after <- DT::renderDT(
DT::datatable(a11y_audit(improved_plot(), level = input$level),
extensions = "Buttons", options = dt_options,
class = "compact stripe hover", rownames = FALSE)
)
}
shinyApp(ui, server)