Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Sep 18, 2024
1 parent f318900 commit abdd3a1
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 7 deletions.
45 changes: 42 additions & 3 deletions R/context_calls.R
Original file line number Diff line number Diff line change
@@ -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)) {
Expand All @@ -16,15 +25,25 @@ 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")
}

#' 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)
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions R/tabulator_context.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion man/add_row.Rd

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

6 changes: 6 additions & 0 deletions man/delete_selected_rows.Rd

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

6 changes: 6 additions & 0 deletions man/redo.Rd

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

6 changes: 6 additions & 0 deletions man/tabulatorContext.Rd

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

16 changes: 13 additions & 3 deletions man/trigger_download.Rd

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

6 changes: 6 additions & 0 deletions man/trigger_get_data.Rd

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

6 changes: 6 additions & 0 deletions man/trigger_get_sheet_data.Rd

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

6 changes: 6 additions & 0 deletions man/undo.Rd

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

0 comments on commit abdd3a1

Please sign in to comment.