From abdd3a1040262a8dcca673b37b51584b73162c8d Mon Sep 17 00:00:00 2001 From: Stefan Kuethe Date: Thu, 19 Sep 2024 01:01:04 +0200 Subject: [PATCH] Add examples --- R/context_calls.R | 45 ++++++++++++++++++++++++++++++++--- R/tabulator_context.R | 5 ++++ man/add_row.Rd | 8 ++++++- man/delete_selected_rows.Rd | 6 +++++ man/redo.Rd | 6 +++++ man/tabulatorContext.Rd | 6 +++++ man/trigger_download.Rd | 16 ++++++++++--- man/trigger_get_data.Rd | 6 +++++ man/trigger_get_sheet_data.Rd | 6 +++++ man/undo.Rd | 6 +++++ 10 files changed, 103 insertions(+), 7 deletions(-) diff --git a/R/context_calls.R b/R/context_calls.R index 6a88183..3036350 100644 --- a/R/context_calls.R +++ b/R/context_calls.R @@ -1,9 +1,18 @@ #' 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 (needs sheetjs: \code{tabulator(..., sheetjs = TRUE)}) +#' @param type (character): csv, json or xlsx #' @param file_name (character, \code{NULL}): File name. -#' @returns tabulator context object #' If \code{NULL}, it is set to \code{"data.{type}"}. +#' @returns tabulator context object +#' @examples +#' \dontrun{ +#' tabulatorContext("table") |> +#' trigger_download("csv", "table-data.csv") +#' } #' @export trigger_download <- function(ctx, type = c("csv", "json", "xlsx"), file_name = NULL) { if (is.null(file_name)) { @@ -16,6 +25,11 @@ trigger_download <- function(ctx, type = c("csv", "json", "xlsx"), file_name = N #' Submit data to R #' @inheritParams trigger_download #' @returns tabulator context object +#' @examples +#' \dontrun{ +#' tabulatorContext("table") |> +#' trigger_get_data() +#' } #' @export trigger_get_data <- function(ctx) { invoke_method(ctx, "getData") @@ -23,8 +37,13 @@ trigger_get_data <- function(ctx) { #' Add row to table #' @inheritParams trigger_download -#' @param row (list | NULL): row data or \code{NULL} to add an empty row +#' @param row (list): row data or \code{NULL} to add an empty row #' @returns tabulator context object +#' @examples +#' \dontrun{ +#' tabulatorContext("table") |> +#' add_row() +#' } #' @export add_row <- function(ctx, row = NULL) { invoke_method(ctx, "addRow", row) @@ -33,6 +52,11 @@ add_row <- function(ctx, row = NULL) { #' Delete selected rows from table #' @inheritParams trigger_download #' @returns tabulator context object +#' @examples +#' \dontrun{ +#' tabulatorContext("table") |> +#' delete_selected_rows() +#' } #' @export delete_selected_rows <- function(ctx) { invoke_method(ctx, "deleteSelectedRows") @@ -47,6 +71,11 @@ delete_row <- function(ctx) { #' Undo changes #' @inheritParams trigger_download #' @returns tabulator context object +#' @examples +#' \dontrun{ +#' tabulatorContext("table") |> +#' undo() +#' } #' @export undo <- function(ctx) { invoke_method(ctx, "undo") @@ -55,6 +84,11 @@ undo <- function(ctx) { #' Redo changes #' @inheritParams trigger_download #' @returns tabulator context object +#' @examples +#' \dontrun{ +#' tabulatorContext("table") |> +#' redo() +#' } #' @export redo <- function(ctx) { invoke_method(ctx, "redo") @@ -63,6 +97,11 @@ redo <- function(ctx) { #' Submit sheet data to R #' @inheritParams trigger_download #' @returns tabulator context object +#' @examples +#' \dontrun{ +#' tabulatorContext("table") |> +#' trigger_get_sheet_data() +#' } #' @export trigger_get_sheet_data <- function(ctx) { invoke_method(ctx, "getSheetData") diff --git a/R/tabulator_context.R b/R/tabulator_context.R index d390588..97d9002 100644 --- a/R/tabulator_context.R +++ b/R/tabulator_context.R @@ -21,6 +21,11 @@ invoke_method <- function(widget, method_name, ...) { #' @param output_id (character): A tabulator output id. #' @param session A shiny session object. #' @returns tabulator context object +#' @examples +#' \dontrun{ +#' tabulatorContext("table") |> +#' trigger_download("csv") +#' } #' @export tabulatorContext <- function(output_id, session = shiny::getDefaultReactiveDomain()) { ctx <- list( diff --git a/man/add_row.Rd b/man/add_row.Rd index e4edbab..76421d3 100644 --- a/man/add_row.Rd +++ b/man/add_row.Rd @@ -9,7 +9,7 @@ add_row(ctx, row = NULL) \arguments{ \item{ctx}{(\code{\link{tabulatorContext}}): tabulator context object} -\item{row}{(list | NULL): row data or \code{NULL} to add an empty row} +\item{row}{(list): row data or \code{NULL} to add an empty row} } \value{ tabulator context object @@ -17,3 +17,9 @@ tabulator context object \description{ Add row to table } +\examples{ +\dontrun{ +tabulatorContext("table") |> + add_row() +} +} diff --git a/man/delete_selected_rows.Rd b/man/delete_selected_rows.Rd index d335b6b..ba8d8e0 100644 --- a/man/delete_selected_rows.Rd +++ b/man/delete_selected_rows.Rd @@ -15,3 +15,9 @@ tabulator context object \description{ Delete selected rows from table } +\examples{ +\dontrun{ +tabulatorContext("table") |> + delete_selected_rows() +} +} diff --git a/man/redo.Rd b/man/redo.Rd index dafff08..6b420b2 100644 --- a/man/redo.Rd +++ b/man/redo.Rd @@ -15,3 +15,9 @@ tabulator context object \description{ Redo changes } +\examples{ +\dontrun{ +tabulatorContext("table") |> + redo() +} +} diff --git a/man/tabulatorContext.Rd b/man/tabulatorContext.Rd index 683fe92..314a50d 100644 --- a/man/tabulatorContext.Rd +++ b/man/tabulatorContext.Rd @@ -20,3 +20,9 @@ Create a tabulator context object \details{ A \code{tabulatorContext} object makes it possible to update your widget in a Shiny application. } +\examples{ +\dontrun{ +tabulatorContext("table") |> + trigger_download("csv") +} +} diff --git a/man/trigger_download.Rd b/man/trigger_download.Rd index 2bb8211..a12f26a 100644 --- a/man/trigger_download.Rd +++ b/man/trigger_download.Rd @@ -9,14 +9,24 @@ trigger_download(ctx, type = c("csv", "json", "xlsx"), file_name = NULL) \arguments{ \item{ctx}{(\code{\link{tabulatorContext}}): tabulator context object} -\item{type}{(character): csv, json or xlsx (needs sheetjs: \code{tabulator(..., sheetjs = TRUE)})} +\item{type}{(character): csv, json or xlsx} -\item{file_name}{(character, \code{NULL}): File name.} +\item{file_name}{(character, \code{NULL}): File name. +If \code{NULL}, it is set to \code{"data.{type}"}.} } \value{ tabulator context object - If \code{NULL}, it is set to \code{"data.{type}"}. } \description{ Download table data } +\details{ +If you want to provide xlsx downloads, you need to include +the sheetjs html dependency: \code{tabulator(..., sheetjs = TRUE)} +} +\examples{ +\dontrun{ +tabulatorContext("table") |> + trigger_download("csv", "table-data.csv") +} +} diff --git a/man/trigger_get_data.Rd b/man/trigger_get_data.Rd index 9c02214..5fa9726 100644 --- a/man/trigger_get_data.Rd +++ b/man/trigger_get_data.Rd @@ -15,3 +15,9 @@ tabulator context object \description{ Submit data to R } +\examples{ +\dontrun{ +tabulatorContext("table") |> + trigger_get_data() +} +} diff --git a/man/trigger_get_sheet_data.Rd b/man/trigger_get_sheet_data.Rd index a312048..76f9ab8 100644 --- a/man/trigger_get_sheet_data.Rd +++ b/man/trigger_get_sheet_data.Rd @@ -15,3 +15,9 @@ tabulator context object \description{ Submit sheet data to R } +\examples{ +\dontrun{ +tabulatorContext("table") |> + trigger_get_sheet_data() +} +} diff --git a/man/undo.Rd b/man/undo.Rd index 08b9a9c..ecddf25 100644 --- a/man/undo.Rd +++ b/man/undo.Rd @@ -15,3 +15,9 @@ tabulator context object \description{ Undo changes } +\examples{ +\dontrun{ +tabulatorContext("table") |> + undo() +} +}