Skip to content

Commit

Permalink
Merge pull request #21 from eodaGmbH/docs/pkg-vignette
Browse files Browse the repository at this point in the history
Add helper for spreadsheet def and update docs
  • Loading branch information
crazycapivara authored Sep 13, 2024
2 parents e9488f2 + 91c2c5e commit 6b87fc3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(set_formatter_toggle_switch)
export(set_formatter_traffic_light)
export(set_header_filter)
export(set_multi_column_header)
export(spreadsheet_def)
export(tabulator)
export(tabulatorContext)
export(tabulatorOutput)
Expand Down
10 changes: 10 additions & 0 deletions R/spreadsheet.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#' 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.
#' @export
spreadsheet_def <- function(title, key = NULL, data = NULL) {
return(compact(as.list(environment())))
}

## #' @export
# TODO: Is this useful?
set_spreadsheet_mode <- function(
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ reference:
desc: >
Utitily functions
contents:
- spreadsheet_def
- list_to_data_frame
- create_columns

19 changes: 19 additions & 0 deletions man/spreadsheet_def.Rd

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

42 changes: 35 additions & 7 deletions vignettes/articles/rtabulator.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ knitr::opts_chunk$set(

rtabulator provides R bindings for [Tabulator JS](https://tabulator.info/).

The goal of rtabulator is to make it easy to create elegant and interactive tables in markdown documents and [Shiny](https://shiny.posit.co/) applications. Furthermore, it support creating spreadsheets with multiple sheets.
The goal of rtabulator is to make it easy to create elegant and interactive tables in markdown documents and [Shiny](https://shiny.posit.co/) applications. Furthermore, it supports creating spreadsheets with multiple sheets.

```{r setup}
library(rtabulator)
```

## Basic Usage

To render a table just pass a data frame to the `tabulator` function:
To render a table just pass a data frame to `tabulator()`:

```{r}
tabulator(airquality)
Expand All @@ -30,7 +30,7 @@ character columns is set to _left_ while numeric columns are aligned _right_.

## Setup Options

With `tabulator_options` you can customize your table (or spreadsheet):
With `tabulator_options()` you can customize your table (or spreadsheet):

```{r}
setup <- tabulator_options(
Expand All @@ -44,7 +44,7 @@ tabulator(USArrests, setup)

## Column Formatters

To customize your columns the easiest way is to use the `set_formatter_*` functions:
To customize your columns, the easiest way is to use the `set_formatter_*` functions like `set_formatter_progress()` and others:

```{r}
tabulator(airquality) |>
Expand All @@ -54,7 +54,7 @@ tabulator(airquality) |>

## Multi Column headers

You can create multi column headers with `set_multi_column_header`:
You can create multi column headers with `set_multi_column_header()`:

```{r}
headers <- list(
Expand All @@ -68,9 +68,37 @@ tabulator(iris) |>

## Spreadsheets

To create an empty spreadsheet just pass an empty list as `data` parameter and `spreadsheet = TRUE`
to the `tabulator` function:
To create an empty spreadsheet just pass an empty list as `data` parameter and `spreadsheet = TRUE` to `tabulator()`:

```{r}
tabulator(data = list(), spreadsheet = TRUE)
```

The data format for spreadsheets is a list of lists or vectors where each entry represents a row in the spreadsheet:

```{r}
spreadsheet_data <- list(
c(1, 2, 3),
c(2, 3, 4)
)
```

To use multiple sheets pass a list of sheets created with`spreadsheet_def()`. In this case, data is passed with the `data` parameter of the sheet definitions:

```{r}
sheets <- list(
spreadsheet_def(title = "Lee", data = spreadsheet_data),
spreadsheet_def(title = "Morgan", data = list()) # Empty spreadsheet
)
setup = tabulator_options(
spreadsheet = TRUE,
spreadsheet_sheets = sheets,
spreadsheet_sheet_tabs = TRUE,
edit_trigger_event = "click"
)
tabulator(NULL, setup)
```
## Next Steps

Check the [API Reference](../reference/index.html) for details.

0 comments on commit 6b87fc3

Please sign in to comment.