Skip to content

Commit

Permalink
add shiny tests and update dfe_reactable docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oadetayo committed Jan 15, 2025
1 parent 6d06dc3 commit 0c38036
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 127 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export(cookies_panel_server)
export(cookies_panel_ui)
export(custom_disconnect_message)
export(dfe_cookies_script)
export(dfe_reactable)
export(external_link)
export(header)
export(init_analytics)
Expand Down
52 changes: 8 additions & 44 deletions R/dfe_reactable.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,6 @@
#' and user-friendly tables tailored to the Department for Education's requirements.
#'
#' @param data A data frame to display in the table.
#' @param columns A named list of column definitions created with `reactable::colDef()`.
#' @param columnGroups A list of column groups created with `reactable::colGroup()`.
#' @param rownames Logical or character. If `TRUE`, show row names. If a string, the row names
#' will be displayed in a column with that name. Defaults to `NULL`.
#' @param groupBy A character vector of column names to group rows by.
#' @param sortable Logical. Enable sorting for all columns by default.
#' @param filterable Logical. Enable column filters.
#' @param searchable Logical. Add a global search box.
#' @param searchMethod Custom search function for global search.
#' @param defaultColDef Default column settings created with `reactable::colDef()`.
#' @param defaultColGroup Default column group settings created with `reactable::colGroup()`.
#' @param defaultSortOrder The default sort order for sortable columns. One of `"asc"` or `"desc"`.
#' @param defaultSorted A named list or character vector of columns to sort by default.
#' @param pagination Logical. Enable pagination.
#' @param defaultPageSize Number of rows to show per page by default.
#' @param showPageSizeOptions Logical. Allow users to change the page size.
#' @param pageSizeOptions A vector of page size options for the page size dropdown.
#' @param paginationType Pagination control type. One of `"numbers"` or `"jump"`.
#' @param showPagination Logical. Show pagination controls.
#' @param showPageInfo Logical. Show page info (e.g., "1–10 of 100 rows").
#' @param minRows Minimum number of rows to show, even when the data has fewer rows.
#' @param paginateSubRows Logical. Paginate sub rows when rows are grouped.
#' @param details A function or formula for creating expandable row details.
#' @param defaultExpanded Logical or character vector. Expand rows by default.
#' @param selection Selection mode. One of `"multiple"`, `"single"`, or `"none"`.
#' @param defaultSelected A character vector of row names or indices to select by default.
#' @param onClick Callback function for row click events.
#' @param striped Logical. Add zebra-striping to rows.
#' @param compact Logical. Make rows compact.
#' @param wrap Logical. Allow cell text to wrap.
#' @param class CSS class to apply to the table.
#' @param style Inline styles to apply to the table.
#' @param rowClass CSS class to apply to each row.
#' @param rowStyle Inline styles to apply to each row.
#' @param width Table width in pixels or as a CSS value.
#' @param height Table height in pixels or as a CSS value.
#' @param meta Arbitrary metadata to include with the table.
#' @param elementId Element ID for the table widget.
#' @param static Logical. Render a static (non-interactive) table.
#' @param selectionId Element ID to store selected row indices.
#' @param ... Additional arguments passed to `reactable::reactable`.
#'
#' @details
Expand All @@ -64,11 +24,15 @@
#'
#' @examples
#' if (interactive()) {
#' library(reactable)
#' dfe_reactable(mtcars)
#' library(shiny)
#' library(dfeshiny)
#' ui <- fluidPage(
#' h1("Example of dfe_reactable in a Shiny app"),
#' dfe_reactable(mtcars)
#' )
#' server <- function(input, output, session) {}
#' shinyApp(ui, server)
#' }
#'
#' @export


dfe_reactable <- function(data, ...) {
Expand Down
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ reference:
desc: A wrapper for shinyGovstyle::header() that automatically uses the DfE logo.
contents:
- header
- title: Charts and Tables
desc: Functions to create and manage tables and visualisations.
contents:
- dfe_reactable
90 changes: 8 additions & 82 deletions man/dfe_reactable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/test_dashboard/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ server <- function(input, output, session) {
input_cookies = shiny::reactive(input$cookies),
google_analytics_key = ga_key # nolint: [object_usage_linter]
)

output$reactable_example <- reactable::renderReactable(dfe_reactable(mtcars))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"output": {

}
}
13 changes: 13 additions & 0 deletions tests/test_dashboard/tests/testthat/test-UI-04-table.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
app <- AppDriver$new(
name = "table_example",
expect_values_screenshot_args = FALSE
)

app$wait_for_idle(50)

test_that("Table renders as expected", {
# Check the initial rendering of the table
app$wait_for_idle(50)
app$expect_values(output = "reactable_example")
})

Check notice

Code scanning / lintr

Trailing blank lines are superfluous. Note test

Trailing blank lines are superfluous.
8 changes: 8 additions & 0 deletions tests/test_dashboard/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ ui <- function(input, output, session) {
),
" code in a cave without distractions."
)
),

## Example table panel --------------------------------------------------------
shiny::tabPanel(
value = "table_panel_ui",
"Table example",
shiny::tags$h1("Reactable example"),
reactable::reactableOutput("reactable_example")
)
)
)
Expand Down

0 comments on commit 0c38036

Please sign in to comment.