From cf4169b9d647073d1dd1a325a41de4feeeff7ae8 Mon Sep 17 00:00:00 2001 From: Stefan Kuethe Date: Tue, 17 Sep 2024 23:12:03 +0200 Subject: [PATCH] Add connected-tables vignette --- R/columns.R | 5 +++ R/tabulator_context.R | 1 + vignettes/articles/connectes-tables.Rmd | 51 +++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 vignettes/articles/connectes-tables.Rmd diff --git a/R/columns.R b/R/columns.R index cb211d0..7a91fca 100644 --- a/R/columns.R +++ b/R/columns.R @@ -36,6 +36,11 @@ set_auto_id <- function(data) { return(data) } + if (nrow(data) == 0) { + data$id <- numeric() + return(data) + } + data$id <- seq(1:nrow(data)) return(data) } diff --git a/R/tabulator_context.R b/R/tabulator_context.R index 6fbfd1d..c649123 100644 --- a/R/tabulator_context.R +++ b/R/tabulator_context.R @@ -15,6 +15,7 @@ invoke_method <- function(widget, method_name, ...) { } #' 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 diff --git a/vignettes/articles/connectes-tables.Rmd b/vignettes/articles/connectes-tables.Rmd new file mode 100644 index 0000000..6063979 --- /dev/null +++ b/vignettes/articles/connectes-tables.Rmd @@ -0,0 +1,51 @@ +--- +title: "Connecting tables" +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(rtabulator) +``` + +With the setup option `movable_rows_connected_tables` you can move rows between two or more tables: + +```{r} +sender_df <- head(iris, 3) +empty_df <- head(iris, 0) + +tab_sender <- tabulator( + sender_df, + tabulator_options( + movable_rows = TRUE, + movable_rows_connected_tables = "#table-receiver", + movable_rows_receiver = "add", + movable_rows_sender = "delete", + placeholder = "All rows moved" + ), + element_id = "table-sender" +) +tab_receiver <- tabulator( + empty_df, + tabulator_options( + placeholder = "Drag rows here" + ), + element_id = "table-receiver" +) + +tab_sender +tab_receiver +``` + +*** + +**Note** + +In some browsers _moving rows functionality_ does not seem to work at the moment. + +***