MyNixOS website logo
Description

'DT' Extension for CRUD (Create, Read, Update, Delete) Applications in 'shiny'.

The core of this package is a function eDT() which enhances DT::datatable() such that it can be used to interactively modify data in 'shiny'. By the use of generic 'dplyr' methods it supports many types of data storage, with relational databases ('dbplyr') being the main use case.

CRAN status R-CMD-check codecov CRAN downloads

editbl allows you to do exactly what is says: 'edit tibbles'. Meaning you can explore and modify any kind of tabular data, independently of where it is stored, in a spreadsheet-like fashion.

The package builds around DT as light weight as possible to provide you with a nice interface to edit your data, while still keeping as much flexibility as possible to customize the table yourself.

Main features by which it distinguishes itself from other CRUD (create, read, update, delete) packages:

  • Supporting multiple backends and in-place editing.
  • Easy customizable shiny integration.
  • undo/redo button
  • No need to have all data in-memory.
  • Developed with focus on relational databases. Tackles challenges such as enforcing foreign keys and hiding of surrogate keys.
  • Transactional commits (currently for tbl_dbi class and non in-place editing).
  • Default values for new rows (UUID's, 'current date', 'inserted by', ...)

Installation

  • From CRAN:
install.packages('editbl')
  • Latest development version:
remotes::install_github("https://github.com/openanalytics/editbl", ref = "main", subdir = "editbl")

Get started

Choose a dataset of your liking and use eDT to interactively explore and modify it!

modifiedData <- editbl::eDT(mtcars)
print(modifiedData)

Run some demo apps

editbl::runDemoApp()

More introductory examples can be found here. Advanced examples can be found in the vignettes.

Switching from DT

Let's say you already use DT::datatable() to display your data, but want to switch to editbl::eDT() to be able to edit it. Would this be a lot of effort? No! In fact, eDT() accepts the exact same arguments. So it is almost as easy as replacing the functions and you are done. Should you run into problems take a look here for some pointers to look out for.

Constraints and normalized tables

Sometimes you want to restrict certain columns of your table to only contain specific values. Many of these restrictions would be implemented at database level through the use of foreign keys to other tables.

editbl allows you to specify similar rules through the use of foreignTbls as an argument to eDT(). Note that you can additionally hide surrogate keys by the use of naturalKey and columnDefs if you wish to.

a <- tibble::tibble(
    first_name = c("Albert","Donald","Mickey"),
    last_name_id = c(1,2,2)
  )

b <-  foreignTbl(
  a,
  tibble::tibble(
      last_name = c("Einstein", "Duck", "Mouse"),
      last_name_id = c(1,2,3)
    ),
  by = "last_name_id",
  naturalKey = "last_name"
)

eDT(a,
  foreignTbls = list(b),
  options = list(columnDefs = list(list(visible=FALSE, targets="last_name_id")))
)

Support for different backends

dplyr code is used for all needed data manipulations and it is recommended to pass on your data as a tbl. This allows editbl to support multiple backends through the usage of other packages like dtplyr, dbplyr etc.

In case you pass on other tabular objects like data.frame or data.table the function will internally automatically cast back and forth to tbl. Small side effects may occur because of this (like loosing rownames), so it might be better to cast yourself to tbl explicitly before passing on data to be in full control.

# tibble support
modifiedData <- editbl::eDT(tibble::as_tibble(mtcars))

# data.frame support
modifiedData <- editbl::eDT(mtcars)

# data.table support
modifiedData <- editbl::eDT(data.table::data.table(mtcars))

# database support
tmpFile <- tempfile(fileext = ".sqlite")
file.copy(system.file("extdata", "chinook.sqlite", package = 'editbl'), tmpFile)
conn <- editbl::connectDB(dbname = tmpFile)
modifiedData <- editbl::eDT(dplyr::tbl(conn, "Artist"), in_place = TRUE)
DBI::dbDisconnect(conn)
unlink(tmpFile)

# excel integration
xlsx_file <- system.file("extdata",
            "artists.xlsx",
            package="editbl")
xlsx_tbl <- tibble::as_tibble(
                  openxlsx::read.xlsx(xlsx_file)
              )
modified <- eDT(xlsx_tbl)
openxlsx::write.xlsx(modified, xlsx_file)

Note that there are some custom methods in the package itself for rows_update / rows_delete / rows_insert. The goal would be to fully rely on dplyr once these functions are not experimental anymore and support all needed requirements. These functions also explain the high amount of 'suggested' packages, while the core functionality of editbl has few dependencies.

Concurrent updates

editbl does not attempt to detect/give notifications on concurrent updates by other users to the same data, nor does it 'lock' the rows you are updating. It just sends its updates to the backend by matching on the keys of a row. If other users have in the meantime made conflicting adjustements, the changes you made might not be executed correctly or errors might be thrown.

Notes

  • https://github.com/tidyverse/dtplyr/issues/260 might cause errors / warnings when using eDT with dtplyr. If possible convert to normal tibble first.
  • editbl assumes that all rows in your table are unique. This assumption is the key (ba dum tss) to allow for only having the data partially in memory.

General future goals for this package

  • Full dplyr compatibility so support for different backends is easily facilitated. Now there are 2 methods (e_rows_update, e_rows_insert) that need to be implemented to support a new backend.
  • Full DT compatibility, including all extensions.
  • Better editing / display options for time values. E.g. control over timezone and format of display / storage + nicer input forms.
  • Any addition that supports the concept of editing data as flexible/easy as possible while respecting backend schema's and constraints.

References

Alternatives

These are other popular CRUD packages in R. Depending on your needs, they might be better alternatives.

DataEditR

  • Rstudio plugin
  • Really flexible excel-like feeling
  • Can only edit in-memory tables. Harder to support databases etc.

editData

  • Rstudio plugin
  • Nice features in terms of editing (pop-ups, more buttons,...)
  • Can only edit in-memory tables. Harder to support databases etc.

Editor

  • Premium datatable extension allowing for editing data.

DT-Editor

  • data.table focused

DTedit

  • DT extension
  • Very customizable (own callbacks)
  • Few dependencies

Additional links:

CRAN DT

CRAN tibble

Blogpost buttons in DT

Blogpost shiny vs excel

Generic CRUD application

Example SQLite databse.

Metadata

Version

1.0.5

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows