Skip to content

Commit

Permalink
fixed optional arguments issue
Browse files Browse the repository at this point in the history
  • Loading branch information
davidruvolo51 committed Feb 8, 2020
1 parent 0b00c24 commit fcba0ac
Show file tree
Hide file tree
Showing 7 changed files with 389 additions and 224 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: accessibleshiny
Type: Package
Title: An accessible components extension for shiny applications
Version: 0.1.1
Version: 0.1.2
Author: dcruvolo
Maintainer: The package maintainer <yourself@somewhere.net>
Description: This package provides a series of ui components for creating
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export("datatable")
export("radios")
importFrom(shiny, addResourcePath)
74 changes: 52 additions & 22 deletions R/datatable.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,31 @@
#' @param id A unique id for the table (required)
#' @param css A character string of css name(s) to render in the table element
#' @param caption A short description (1-2 lines) for the table (optional)
#' @param style a list of options to control the appearance of the app
#' @param rowHighlighting a logical value when true will highlight odd rows
#' @param options A list of options to pass on to the render table method
#' @param responsive A logical arg for turning on/off the rendering of
#' @parma ... Other list object used to control the component. See the next
#' section and the wiki for more information.
#'
#' @section Optional Arguments
#' Using \code{...}, you can pass additional arguments that allow you to
#' control the markup, css attributes, etc. These arguments must be passed
#' as list objects through \code{style = list()} or by using
#' \code{options = list()}. These arguments are explained below. See the wiki
#' for more information.
#' \code{style} a list of options to control the appearance of the app
#' \code{enabled} When TRUE (default), all css classes will be applied.
#' FALSE will return a table with no css classes. This will also
#' overide the argument \code{loadDependency}, \code{responsive},
#' \code{rowHighlighting} a logical value when true will highlight odd rows
#' \code{options} A list of options to pass on to the render table method
#' \code{responsive} A logical arg for turning on/off the rendering of
#' additional elements for a responsive tables (default = FALSE)
#' @param rowHeaders a logical argument when true sets the first cell
#' \code{rowHeaders} a logical argument when true sets the first cell
#' of every row as a header element (default = FALSE).
#' @asHTML A logical argument when true will render cell values as
#' \code{asHTML} A logical argument when true will render cell values as
#' html elements (default = FALSE)
#'
#' \code{loadDependency} When TRUE (default), the function will load the
#' corresponding css files into the header document. FALSE will
#' not load datatable dependencies.
#'
#' @examples
#' datatable(data = iris, id = "iris-table")
#'
Expand All @@ -44,23 +59,34 @@
#' \code{options = list(...)} for addtional rendering options.
#' @keywords datatable a11y
#' @author dcruvolo
#' @importFrom htmltools singleton htmlDependencies tags
#' @importFrom htmltools tags
#'
datatable <- function(data, id = NULL, caption = NULL, css = NULL,
style = list(rowHighlighting = TRUE),
options = list(responsive = TRUE, rowHeaders = TRUE, asHTML = FALSE)) {
datatable <- function(data, id = NULL, caption = NULL, css = NULL, ...) {

# validate args: send `...` down to validation function. The returned
# output is nested lists. To access optiions and props, use `props$style`
# or `props$options`.
props <- datatable_helpers$validate_props(...)

# render table and table elements
tbl <- htmltools::tags$table(
class = datatable_helpers$datatable_css(css = css, style = style),
datatable_helpers$build_header(data, options),
datatable_helpers$build_body(data, options)
datatable_helpers$build_header(
data = data,
options = props$options
),
datatable_helpers$build_body(
data = data,
style = props$style,
options = props$options
)
)

# add id
if (length(id) > 0) {
tbl$attribs$id <- id
}
# update table attributes - apply css only if style$enabled == TRUE
tbl$attribs <- datatable_helpers$set_table_attributes(
id = id,
css = css,
style = props$style
)

# should a caption be rendered?
if (length(caption) > 0) {
Expand All @@ -70,9 +96,13 @@ options = list(responsive = TRUE, rowHeaders = TRUE, asHTML = FALSE)) {
)
}

# load css from ww/css/datatables.css and return tbl
htmltools::tagList(
datatable_helpers$datatable_dependencies(),
# load css from ww/css/datatables.css if applicable
if (isFALSE(props$style$enabled) | isFALSE(props$options$loadDependency)) {
tbl
)
} else {
htmltools::tagList(
datatable_helpers$load_dependencies(),
tbl
)
}
}
Loading

1 comment on commit fcba0ac

@davidruvolo51
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit addresses issue #3

Please sign in to comment.