Skip to content

Commit

Permalink
Merge pull request #39 from eodaGmbH/prepare-cran-release
Browse files Browse the repository at this point in the history
Prepare cran release
  • Loading branch information
crazycapivara authored Sep 20, 2024
2 parents b625a28 + 5d81b71 commit 6d90373
Show file tree
Hide file tree
Showing 44 changed files with 214 additions and 224 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Imports:
glue,
htmltools,
Expand Down
74 changes: 29 additions & 45 deletions R/columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ add_filter_to_columns <- function(columns) {
}

#' Apply a column setter function to multiple columns
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param columns (character vector): The columns the column setter function (\code{.f}) is applied to.
#' If set to \code{NULL} it is applied to all columns.
#' If set to \code{NULL}, it is applied to all columns.
#' @param .f (function): The column setter function that updates the column settings.
#' @param ... Arguments that are passed to \code{.f}.
#' @returns tabulator htmlwidget
#' @example examples/for_each_col.R
#' @export
for_each_col <- function(widget, columns = NULL, .f, ...) {
Expand All @@ -90,10 +89,10 @@ for_each_col <- function(widget, columns = NULL, .f, ...) {
# TODO: Move formatters to separate file

#' Set HTML formatter
#' @param widget (\code{\link{tabulator}}) A tabulator widget.
#' @param column (character): The column the formatter is applied to.
#' @param widget A [tabulator()] HTML widget.
#' @param column The name of the column the formatter is applied to.
#' @param hoz_align (character): The horizontal alignment of the column.
#' @returns tabulator htmlwidget
#' @returns The updated [tabulator()] HTML widget
#' @example examples/formatters/formatter_html.R
#' @export
set_formatter_html <- function(widget, column, hoz_align = c("left", "center", "right")) {
Expand All @@ -102,27 +101,27 @@ set_formatter_html <- function(widget, column, hoz_align = c("left", "center", "
}

#' Set plain text formatter
#' @inheritParams set_formatter_html
#' @returns tabulator htmlwidget
#' @inherit set_formatter_html params return
#' @examples
#' tabulator(iris) |>
#' set_formatter_plaintext("Species", hoz_align = "right")
#' @export
# TODO: Add example
set_formatter_plaintext <- function(widget, column, hoz_align = "left") {
col_update <- list(formatter = "plaintext", hozAlign = hoz_align)
modify_col_def(widget, column, col_update)
}

#' Set textarea formatter
#' @inheritParams set_formatter_html
#' Set text area formatter
#' @inherit set_formatter_html params return
#' @example examples/formatters/formatter_textarea.R
#' @returns tabulator htmlwidget
#' @export
set_formatter_textarea <- function(widget, column, hoz_align = "left") {
col_update <- list(formatter = "textarea", hozAlign = hoz_align)
modify_col_def(widget, column, col_update)
}

#' Set money formatter
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param decimal (character): Symbol to represent the decimal point.
#' @param thousand (character, bool): Symbol to represent the thousands separator.
#' Set to \code{FALSE} to disable the separator.
Expand All @@ -133,7 +132,6 @@ set_formatter_textarea <- function(widget, column, hoz_align = "left") {
#' which is the standard style for negative numbers in accounting.
#' @param precision (integer, bool): The number of decimals to display.
#' Set to \code{FALSE} to display all decimals that are provided.
#' @returns tabulator htmlwidget
#' @example examples/formatters/formatter_money.R
#' @export
set_formatter_money <- function(
Expand Down Expand Up @@ -163,14 +161,13 @@ set_formatter_money <- function(
}

#' Set image formatter
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param height (character): A CSS value for the height of the image.
#' @param width (character): A CSS value for the width of the image.
#' @param url_prefix (character): String to add to the start of the cell value
#' when generating the image src url.
#' @param url_suffix (character): String to add to the end of the cell value
#' when generating the image src url.
#' @returns tabulator htmlwidget
#' @example examples/formatters/formatter_image.R
#' @export
set_formatter_image <- function(
Expand All @@ -196,14 +193,13 @@ set_formatter_image <- function(
}

#' Set link formatter
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param label_field (character): Column to be used as label for the link.
#' @param url_prefix (character): Prefix to add to the URL value.
#' @param url (JS function): A JS function that return the URL value.
#' @param url (JavaScript function): A JavaScript function that return the URL value.
#' The cell is passed to the function as its first argument.
#' Use \link[htmlwidgets]{JS} to pass JS code.
#' @param target (character): Target attribute of the anchor tag.
#' @returns tabulator htmlwidget
#' @example examples/formatters/formatter_link.R
#' @export
set_formatter_link <- function(
Expand All @@ -229,10 +225,9 @@ set_formatter_link <- function(
}

#' Set star rating formatter
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param number_of_stars The maximum number of stars to be displayed.
#' If set to \code{NA}, the maximum value of the column is used.
#' @returns tabulator htmlwidget
#' @example examples/formatters/formatter_star.R
#' @export
set_formatter_star <- function(widget, column, number_of_stars = NA, hoz_align = "center") {
Expand All @@ -249,7 +244,7 @@ set_formatter_star <- function(widget, column, number_of_stars = NA, hoz_align =
}

#' Set progress formatter
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param min (numeric): The minimum value for progress bar.
#' If set to \code{NA}, the minimum value of the column is used.
#' @param max (numeric): The maximum value for progress bar.
Expand All @@ -261,7 +256,6 @@ set_formatter_star <- function(widget, column, number_of_stars = NA, hoz_align =
#' In this case, the cell value is passed to the function as its first argument.
#' @param legend_color (character): The text color of the legend.
#' @param legend_align (character): The text alignment of the legend.
#' @returns tabulator htmlwidget
#' @example examples/formatters/formatter_progress.R
#' @export
set_formatter_progress <- function(
Expand Down Expand Up @@ -299,25 +293,23 @@ set_formatter_progress <- function(
}

#' Set tick cross formatter
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @example examples/formatters/formatter_tick_cross.R
#' @returns tabulator htmlwidget
#' @export
set_formatter_tick_cross <- function(widget, column, hoz_align = "center") {
col_update <- list(formatter = "tickCross", hozAlign = hoz_align)
modify_col_def(widget, column, col_update)
}

#' Set toggle switch formatter
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param size (numeric): The size of the switch in pixels.
#' @param on_value (character): The value of the cell for the switch to be on.
#' @param off_value (character) The value of the cell for the switch to be off.
#' @param on_truthy (bool): Whether to show the switch as on if the value of the cell is truthy.
#' @param on_color (character): The color of the switch if it is on.
#' @param off_color (character): The color of the switch if it is off.
#' @param clickable (bool): Enable switch functionality to toggle the cell value on click.
#' @returns tabulator htmlwidget
#' @example examples/formatters/formatter_toggle_switch.R
#' @export
set_formatter_toggle_switch <- function(
Expand Down Expand Up @@ -349,15 +341,14 @@ set_formatter_toggle_switch <- function(
#' Set datetime formatter
#'
#' @details
#' To use this formatter, you need to include the luxon html dependency
#' when creating a tabulator widget.
#' @inheritParams set_formatter_html
#' To use this formatter, you need to include
#' the [luxon](https://moment.github.io/luxon/) HTML dependency with `tabulator(..., luxon = TRUE)`.
#' @inherit set_formatter_html params return
#' @param input_format (character): The datetime input format.
#' @param output_format (character): The datetime output format.
#' @param invalid_placeholder (character): The value to be displayed
#' if an invalid datetime is provided.
#' @param timezone (character): The timezone of the datetime.
#' @returns tabulator htmlwidget
#' @example examples/formatters/formatter_datetime.R
#' @export
set_formatter_datetime <- function(
Expand All @@ -383,8 +374,7 @@ set_formatter_datetime <- function(
}

#' Set color formatter
#' @inheritParams set_formatter_html
#' @returns tabulator htmlwidget
#' @inherit set_formatter_html params return
#' @example examples/formatters/formatter_color.R
#' @export
set_formatter_color <- function(widget, column) {
Expand All @@ -393,8 +383,7 @@ set_formatter_color <- function(widget, column) {
}

#' Set traffic light formatter
#' @inheritParams set_formatter_progress
#' @returns tabulator htmlwidget
#' @inherit set_formatter_progress params return
#' @example examples/formatters/formatter_traffic_light.R
#' @export
set_formatter_traffic_light <- function(
Expand Down Expand Up @@ -439,11 +428,10 @@ set_column_editor <- function(widget, columns, type = c("input", "number")) {
}

#' Set editor
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param editor (character): The editor type.
#' @param validator (character vector): One or more validators to validate user input.
#' @param ... Optional editor parameters depending on the selected editor.
#' @returns tabulator htmlwidget
#' @seealso
#' * \url{https://tabulator.info/docs/6.2/edit} for available editors
#' * \url{https://tabulator.info/docs/6.2/validate} for available validators
Expand All @@ -470,13 +458,12 @@ set_editor <- function(
}

#' Set header filter
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param type (character): The type of the filter.
#' @param values_lookup (bool): Whether to use unique column values for the list filter.
#' @param func (character): The filter function.
#' @param clearable (bool): Whether to display a cross to clear the filter.
#' @param placeholder (character): Text that is displayed when no filter is set.
#' @returns tabulator htmlwidget
#' @example examples/misc/header_filter.R
#' @export
# TODO: Rename to params that they match params used by Tabulator JS
Expand Down Expand Up @@ -511,8 +498,7 @@ set_header_filter <- function(
}

#' Set tooltip
#' @inheritParams set_formatter_html
#' @returns tabulator htmlwidget
#' @inherit set_formatter_html params return
#' @example examples/misc/tooltip.R
#' @export
set_tooltip <- function(widget, column) {
Expand All @@ -521,7 +507,7 @@ set_tooltip <- function(widget, column) {


#' Set column defaults
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param editor (character, bool): One of \code{"input"} or \code{"number"}.
#' If set to \code{FALSE} cells are not editable.
#' @param header_filter (character, bool): One of \code{"input"} or \code{"number"}.
Expand All @@ -530,7 +516,6 @@ set_tooltip <- function(widget, column) {
#' @param tooltip (bool): Whether to show tooltips displaying the cell value.
#' @param width (integer): Fixed width of columns.
#' @param ... Additional settings.
#' @returns tabulator htmlwidget
#' @seealso \url{https://tabulator.info/docs/6.2/columns#defaults}
#' @example examples/column_defaults.R
#' @export
Expand All @@ -555,14 +540,13 @@ set_column_defaults <- function(
}

#' Set calculation
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param column (character): The column the \code{func} is applied to.
#' @param func (character): The calculation function to be applied
#' to the values of the \code{column}.
#' @param precision (integer) The number of decimals to display.
#' Set to \code{FALSE} to display all decimals.
#' @param pos (character): Position at which calculated values are displayed.
#' @returns tabulator htmlwidget
#' @example examples/data_url.R
#' @export
set_calculation <- function(
Expand Down
31 changes: 12 additions & 19 deletions R/context_calls.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#' Download table data
#'
#' @details
#' If you want to provide xlsx downloads, you need to include
#' the sheetjs html dependency: \code{tabulator(..., sheetjs = TRUE)}
#' @param ctx (\code{\link{tabulatorContext}}): tabulator context object
#' @param type (character): csv, json or xlsx
#' @param file_name (character, \code{NULL}): File name.
#' If \code{NULL}, it is set to \code{"data.{type}"}.
#' @returns tabulator context object
#' If you want to support `xlsx` downloads, you need to include
#' the [sheetjs](https://sheetjs.com/) HTML dependency with `tabulator(..., sheetjs = TRUE)`.
#' @param ctx A [tabulatorContext()] object.
#' @param type File format.
#' @param file_name File name. Set to `"data.{type}"` if `file_name = NULL`.
#' @returns A [tabulatorContext()] object
#' @examples
#' \dontrun{
#' tabulatorContext("table") |>
Expand All @@ -23,8 +22,7 @@ trigger_download <- function(ctx, type = c("csv", "json", "xlsx"), file_name = N
}

#' Submit data to R
#' @inheritParams trigger_download
#' @returns tabulator context object
#' @inherit trigger_download params return
#' @examples
#' \dontrun{
#' tabulatorContext("table") |>
Expand All @@ -36,9 +34,8 @@ trigger_get_data <- function(ctx) {
}

#' Add row to table
#' @inheritParams trigger_download
#' @inherit trigger_download params return
#' @param row (list): row data or \code{NULL} to add an empty row
#' @returns tabulator context object
#' @examples
#' \dontrun{
#' tabulatorContext("table") |>
Expand All @@ -50,8 +47,7 @@ add_row <- function(ctx, row = NULL) {
}

#' Delete selected rows from table
#' @inheritParams trigger_download
#' @returns tabulator context object
#' @inherit trigger_download params return
#' @examples
#' \dontrun{
#' tabulatorContext("table") |>
Expand All @@ -69,8 +65,7 @@ delete_row <- function(ctx) {
}

#' Undo changes
#' @inheritParams trigger_download
#' @returns tabulator context object
#' @inherit trigger_download params return
#' @examples
#' \dontrun{
#' tabulatorContext("table") |>
Expand All @@ -82,8 +77,7 @@ undo <- function(ctx) {
}

#' Redo changes
#' @inheritParams trigger_download
#' @returns tabulator context object
#' @inherit trigger_download params return
#' @examples
#' \dontrun{
#' tabulatorContext("table") |>
Expand All @@ -95,8 +89,7 @@ redo <- function(ctx) {
}

#' Submit sheet data to R
#' @inheritParams trigger_download
#' @returns tabulator context object
#' @inherit trigger_download params return
#' @examples
#' \dontrun{
#' tabulatorContext("table") |>
Expand Down
10 changes: 8 additions & 2 deletions R/experimental.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# See example here: https://github.com/eodaGmbH/py-tabulator/blob/main/docs/examples/getting_started/shiny_core_multi_row_headers.py
#' Set multi column header
#' @inheritParams set_formatter_html
#' @inherit set_formatter_html params return
#' @param multi_columns (list): Multi column definitions.
#' @returns tabulator htmlwidget
#' @example examples/experimental/multi_column_header.R
#' @export
set_multi_column_header <- function(widget, multi_columns) {
Expand Down Expand Up @@ -46,3 +45,10 @@ get_theme_dependeny <- function(
all_files = FALSE
)
}

# -----
# #' Test docs
# #' @inherit set_formatter_html params return
test_column_func <- function(widget, column) {
return(widget)
}
14 changes: 8 additions & 6 deletions R/spreadsheet.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#' Create a spreadsheet definition
#' @param title (character): The name of the spreadsheet.
#' @param key (character): Optional unique key of the spreadsheet.
#' @param data (list): The initial data of the spreadsheet.
#' Set to \code{NULL} to create an empty spreadsheet.
#' @returns list
#' Spreadsheet definition for `tabulator()` HTML widget
#'
#' @param title Name of the spreadsheet.
#' @param key Unique key of the spreadsheet.
#' @param data Initial data of the spreadsheet.
#' Set to `NULL` to create an empty spreadsheet.
#' @returns list with spreadsheet options to be used as a sheet of the
#' `spreadsheet_sheets` parameter in [tabulator_options()]
#' @example examples/multiple_spreadsheets.R
#' @export
spreadsheet_def <- function(title, key = NULL, data = NULL) {
Expand Down
Loading

0 comments on commit 6d90373

Please sign in to comment.