diff --git a/DESCRIPTION b/DESCRIPTION index 02c13a0..958874b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: rtabulator Type: Package Title: R Bindings for Tabulator JS -Version: 0.1.0 -Date: 2024-09-08 +Version: 0.1.1 +Date: 2024-09-13 Authors@R: c( person("Stefan", "Kuethe", email = "crazycapivara@gmail.com", role = c("aut", "cre")), person("Nico", "Friess", email = "nico.friess@eoda.de", role = c("aut")) @@ -10,6 +10,10 @@ Authors@R: c( Maintainer: Stefan Kuethe Description: Provides R bindings for 'Tabulator JS' . Makes it a breeze to create beautiful interactive tables. +URL: + https://github.com/eodaGmbH/rtabulator + https://eodagmbh.github.io/rtabulator/ +BugReports: https://github.com/eodaGmbH/rtabulator/issues License: MIT + file LICENSE Encoding: UTF-8 LazyData: true diff --git a/NEWS.md b/NEWS.md index f7b2329..e67bf6d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# rtabulator 0.1.1 + +* Update docs +* Add pkgdown site +* Add function to create multi column headers +* Add a lot of examples +* Update README +* Make `devtools::check()` pass 🚀 + # rtabulator 0.1.0 * Add NEWS.md to track changes. diff --git a/R/columns.R b/R/columns.R index 14788c3..8dfa8dd 100644 --- a/R/columns.R +++ b/R/columns.R @@ -1,4 +1,4 @@ -#' Create columns definition from data +#' Create column definitions from data #' @param data (data.frame) data #' @param editor (bool): Whether to make columns editable. #' @param filter (bool): Whether to add a header filter to the columns. @@ -313,8 +313,7 @@ set_formatter_datetime <- function( input_format = "yyyy-MM-dd hh:ss:mm", output_format = "yy/MM/dd", invalid_placeholder = "(invalid datetime)", - timezone = NA - ) { + timezone = NA) { # Body col_update <- list( formatter = "datetime", @@ -339,6 +338,7 @@ set_formatter_color <- function(widget, column) { #' Traffic Light Formatter #' @inheritParams set_formatter_progress +#' @example examples/formatters/formatter_traffic_light.R #' @export set_formatter_traffic_light <- function( widget, @@ -348,9 +348,9 @@ set_formatter_traffic_light <- function( color = c("green", "orange", "red"), hoz_align = "center") { # Body - if (is.na(min)) min = min(widget$x$data[column]) + if (is.na(min)) min <- min(widget$x$data[column]) - if (is.na(max)) max = max(widget$x$data[column]) + if (is.na(max)) max <- max(widget$x$data[column]) col_update <- list( formatter = "traffic", diff --git a/R/tabulator.R b/R/tabulator.R index fd445d9..9ef2613 100644 --- a/R/tabulator.R +++ b/R/tabulator.R @@ -12,6 +12,7 @@ #' @param height Height of the widget. #' @param element_id The unique ID of the widget. #' @param ... Named arguments that are appended to the \code{options} parameter. +#' @example examples/multiple_spreadsheets.R #' @import htmlwidgets #' @export tabulator <- function( diff --git a/R/tabulator_context.R b/R/tabulator_context.R index 950c4d3..6fbfd1d 100644 --- a/R/tabulator_context.R +++ b/R/tabulator_context.R @@ -14,7 +14,8 @@ invoke_method <- function(widget, method_name, ...) { invisible(widget) } -#' Create a Tabulator Context +#' Create a Tabulator Context Object +#' A \code{tabulatorContext} object makes it possible to update your widget in a Shiny app. #' @param output_id (character): A tabulator output id. #' @param session shiny session object #' @export diff --git a/R/tabulator_options.R b/R/tabulator_options.R index f38b646..0bb2be7 100644 --- a/R/tabulator_options.R +++ b/R/tabulator_options.R @@ -32,6 +32,7 @@ #' @param spreadsheet_sheet_tabs (bool): Whether to show sheet tabs in the footer. #' @param ... Further options. #' @seealso \url{https://tabulator.info/docs/6.2/options} +#' @example examples/tabulator_setup.R #' @export tabulator_options <- function( # General diff --git a/_pkgdown.yml b/_pkgdown.yml index d71acfb..448e27e 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -2,3 +2,39 @@ url: ~ template: bootstrap: 5 +reference: + - title: Tabulator Widget + desc: > + Functions to create and setup a Tabulator widget + contents: + - tabulator + - tabulator_options + - set_column_editor + - set_header_filter + - set_multi_column_header + + - title: Column Formatters + desc: > + Functions to set column formatters + contents: + - starts_with("set_formatter") + + - title: Shiny Integration + contents: + - rtabulator-shiny + - tabulatorContext + - add_row + - delete_selected_rows + - trigger_download + - trigger_get_data + - trigger_get_spreadsheet_data + - undo + - redo + + - title: Utils + desc: > + Utitily functions + contents: + - list_to_data_frame + - create_columns + diff --git a/examples/formatters/formatter_datetime.R b/examples/formatters/formatter_datetime.R index 43c949d..1ec37e5 100644 --- a/examples/formatters/formatter_datetime.R +++ b/examples/formatters/formatter_datetime.R @@ -1,6 +1,6 @@ data <- data.frame( Person = c("Franz", "Ferdinand"), - Birthday =c( + Birthday = c( "2024-12-06 22:00:10", "2023-06-07 14:12:45" ) diff --git a/examples/formatters/formatter_html.R b/examples/formatters/formatter_html.R index b0b0ea7..7b1ae1f 100644 --- a/examples/formatters/formatter_html.R +++ b/examples/formatters/formatter_html.R @@ -11,5 +11,5 @@ data <- data.frame( ) ) -tabulator(data, width=200) |> +tabulator(data, width = 400) |> set_formatter_html("text_style") diff --git a/examples/formatters/formatter_money.R b/examples/formatters/formatter_money.R index 05c3899..1934129 100644 --- a/examples/formatters/formatter_money.R +++ b/examples/formatters/formatter_money.R @@ -1,14 +1,14 @@ data <- data.frame( - Account_Number= c( - 123456, - 345667, - 234567, - 234566 - ), + Account_Number = c( + 123456, + 345667, + 234567, + 234566 + ), Account_Balance = c(100, -50, 200.30, -21.5) ) -tabulator(data, width = 300) |> +tabulator(data) |> set_formatter_money( "Account_Balance", symbol = "\U20AC", diff --git a/examples/formatters/formatter_progress.R b/examples/formatters/formatter_progress.R index 033f558..2381052 100644 --- a/examples/formatters/formatter_progress.R +++ b/examples/formatters/formatter_progress.R @@ -7,7 +7,7 @@ data <- data.frame( js_func <- htmlwidgets::JS("(cellValue) => `${cellValue}%`") -tabulator(data, width = 300) |> +tabulator(data) |> set_formatter_progress("value") |> set_formatter_progress("value2", legend = TRUE, legend_align = "left") |> set_formatter_progress("value3", legend = js_func, legend_align = "right") diff --git a/examples/formatters/formatter_textarea.R b/examples/formatters/formatter_textarea.R index 24c6cc6..4ccde07 100644 --- a/examples/formatters/formatter_textarea.R +++ b/examples/formatters/formatter_textarea.R @@ -3,7 +3,7 @@ data <- data.frame( txt = c( "This\nis\nsome\ntext\nwith\nmultiple\nline\nbreaks", "- R\n- Python\n- Julia" - ) + ) ) tabulator(data, width = 200) |> diff --git a/examples/formatters/formatter_tick_cross.R b/examples/formatters/formatter_tick_cross.R index 631091b..cdb8fe2 100644 --- a/examples/formatters/formatter_tick_cross.R +++ b/examples/formatters/formatter_tick_cross.R @@ -2,7 +2,7 @@ data <- data.frame( Artist = c("Art Blackey", "Nirvana", "Bob Marley"), Grunge = c(0, 1, 0), Jazz = c(1, 0, 0), - Reggae = c(0,0,1) + Reggae = c(0, 0, 1) ) tabulator(data, width = 400) |> diff --git a/examples/multiple_spreadsheets.R b/examples/multiple_spreadsheets.R index 28a2e1f..109ed3d 100644 --- a/examples/multiple_spreadsheets.R +++ b/examples/multiple_spreadsheets.R @@ -1,4 +1,4 @@ -options <- tabulator_options( +setup <- tabulator_options( spreadsheet = TRUE, spreadsheet_sheets = list( list( @@ -13,4 +13,4 @@ options <- tabulator_options( spreadsheet_sheet_tabs = TRUE ) -tabulator(data = NULL, options, theme = "midnight") +tabulator(data = NULL, setup, theme = "midnight") diff --git a/examples/tabulator_setup.R b/examples/tabulator_setup.R new file mode 100644 index 0000000..fafaa75 --- /dev/null +++ b/examples/tabulator_setup.R @@ -0,0 +1,9 @@ +setup <- tabulator_options( + group_by = "Species", + pagination = TRUE, + pagination_size = 10, + pagination_size_selector = c(10, 20, 50), + movable_columns = TRUE, + movable_rows = TRUE +) +tabulator(iris, setup) diff --git a/man/create_columns.Rd b/man/create_columns.Rd index eedca93..392a5f3 100644 --- a/man/create_columns.Rd +++ b/man/create_columns.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/columns.R \name{create_columns} \alias{create_columns} -\title{Create columns definition from data} +\title{Create column definitions from data} \usage{ create_columns(data, editor = FALSE, filter = FALSE) } @@ -14,5 +14,5 @@ create_columns(data, editor = FALSE, filter = FALSE) \item{filter}{(bool): Whether to add a header filter to the columns.} } \description{ -Create columns definition from data +Create column definitions from data } diff --git a/man/set_formatter_datetime.Rd b/man/set_formatter_datetime.Rd index 22788a7..815b0f1 100644 --- a/man/set_formatter_datetime.Rd +++ b/man/set_formatter_datetime.Rd @@ -32,7 +32,7 @@ Datetime Formatter \examples{ data <- data.frame( Person = c("Franz", "Ferdinand"), - Birthday =c( + Birthday = c( "2024-12-06 22:00:10", "2023-06-07 14:12:45" ) diff --git a/man/set_formatter_html.Rd b/man/set_formatter_html.Rd index 8651797..3dce810 100644 --- a/man/set_formatter_html.Rd +++ b/man/set_formatter_html.Rd @@ -30,6 +30,6 @@ data <- data.frame( ) ) -tabulator(data, width=200) |> +tabulator(data, width = 400) |> set_formatter_html("text_style") } diff --git a/man/set_formatter_money.Rd b/man/set_formatter_money.Rd index 753fe18..fd3e7e6 100644 --- a/man/set_formatter_money.Rd +++ b/man/set_formatter_money.Rd @@ -44,16 +44,16 @@ Money Formatter } \examples{ data <- data.frame( - Account_Number= c( - 123456, - 345667, - 234567, - 234566 - ), + Account_Number = c( + 123456, + 345667, + 234567, + 234566 + ), Account_Balance = c(100, -50, 200.30, -21.5) ) -tabulator(data, width = 300) |> +tabulator(data) |> set_formatter_money( "Account_Balance", symbol = "\U20AC", diff --git a/man/set_formatter_progress.Rd b/man/set_formatter_progress.Rd index 646c3e1..2d9a3cc 100644 --- a/man/set_formatter_progress.Rd +++ b/man/set_formatter_progress.Rd @@ -53,7 +53,7 @@ data <- data.frame( js_func <- htmlwidgets::JS("(cellValue) => `${cellValue}\%`") -tabulator(data, width = 300) |> +tabulator(data) |> set_formatter_progress("value") |> set_formatter_progress("value2", legend = TRUE, legend_align = "left") |> set_formatter_progress("value3", legend = js_func, legend_align = "right") diff --git a/man/set_formatter_textarea.Rd b/man/set_formatter_textarea.Rd index b149e17..7be2634 100644 --- a/man/set_formatter_textarea.Rd +++ b/man/set_formatter_textarea.Rd @@ -22,7 +22,7 @@ data <- data.frame( txt = c( "This\nis\nsome\ntext\nwith\nmultiple\nline\nbreaks", "- R\n- Python\n- Julia" - ) + ) ) tabulator(data, width = 200) |> diff --git a/man/set_formatter_tick_cross.Rd b/man/set_formatter_tick_cross.Rd index fe0f88e..b3ae3ed 100644 --- a/man/set_formatter_tick_cross.Rd +++ b/man/set_formatter_tick_cross.Rd @@ -19,7 +19,7 @@ data <- data.frame( Artist = c("Art Blackey", "Nirvana", "Bob Marley"), Grunge = c(0, 1, 0), Jazz = c(1, 0, 0), - Reggae = c(0,0,1) + Reggae = c(0, 0, 1) ) tabulator(data, width = 400) |> diff --git a/man/set_formatter_traffic_light.Rd b/man/set_formatter_traffic_light.Rd index 05eb3f2..2d0d91d 100644 --- a/man/set_formatter_traffic_light.Rd +++ b/man/set_formatter_traffic_light.Rd @@ -31,3 +31,13 @@ If set to \code{NA} the maximum value of the column is used.} \description{ Traffic Light Formatter } +\examples{ +data <- data.frame( + label = 1:10, + value = 1:10 +) + +tabulator(data, width = 200) |> + set_formatter_traffic_light("value") |> + set_formatter_plaintext("label", hoz_align = "center") +} diff --git a/man/tabulator.Rd b/man/tabulator.Rd index 8f7de15..b065b50 100644 --- a/man/tabulator.Rd +++ b/man/tabulator.Rd @@ -41,3 +41,21 @@ which is needed for xlsx downloads.} \description{ Dots in column names are replaced by underscores. } +\examples{ +setup <- tabulator_options( + spreadsheet = TRUE, + spreadsheet_sheets = list( + list( + title = "First", + data = list(c(1, 2, 3)) + ), + list( + title = "Second", + data = list(c(4, 5, 6)) + ) + ), + spreadsheet_sheet_tabs = TRUE +) + +tabulator(data = NULL, setup, theme = "midnight") +} diff --git a/man/tabulatorContext.Rd b/man/tabulatorContext.Rd index da7355a..ac3ec60 100644 --- a/man/tabulatorContext.Rd +++ b/man/tabulatorContext.Rd @@ -2,7 +2,8 @@ % Please edit documentation in R/tabulator_context.R \name{tabulatorContext} \alias{tabulatorContext} -\title{Create a Tabulator Context} +\title{Create a Tabulator Context Object +A \code{tabulatorContext} object makes it possible to update your widget in a Shiny app.} \usage{ tabulatorContext(output_id, session = shiny::getDefaultReactiveDomain()) } @@ -12,5 +13,6 @@ tabulatorContext(output_id, session = shiny::getDefaultReactiveDomain()) \item{session}{shiny session object} } \description{ -Create a Tabulator Context +Create a Tabulator Context Object +A \code{tabulatorContext} object makes it possible to update your widget in a Shiny app. } diff --git a/man/tabulator_options.Rd b/man/tabulator_options.Rd index c6f6f31..010a369 100644 --- a/man/tabulator_options.Rd +++ b/man/tabulator_options.Rd @@ -97,6 +97,17 @@ An integer value sets the maximum number of rows that can be selected.} \description{ Tabulator Setup Options } +\examples{ +setup <- tabulator_options( + group_by = "Species", + pagination = TRUE, + pagination_size = 10, + pagination_size_selector = c(10, 20, 50), + movable_columns = TRUE, + movable_rows = TRUE +) +tabulator(iris, setup) +} \seealso{ \url{https://tabulator.info/docs/6.2/options} }