Title: | 'DT' Extension for CRUD (Create, Read, Update, Delete) Applications in 'shiny' |
---|---|
Description: | 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. |
Authors: | Jasper Schelfhout [aut, cre], Maxim Nazarov [rev], Daan Seynaeve [rev], Lennart Tuijnder [rev] |
Maintainer: | Jasper Schelfhout <[email protected]> |
License: | GPL-3 |
Version: | 1.1.0 |
Built: | 2025-03-02 06:05:41 UTC |
Source: | https://github.com/openanalytics/editbl |
Add modification buttons as a column
addButtons( df, columnName, ns, iCol = "i", canEditRow = TRUE, canDeleteRow = TRUE, statusCol = "status" )
addButtons( df, columnName, ns, iCol = "i", canEditRow = TRUE, canDeleteRow = TRUE, statusCol = "status" )
df |
|
columnName |
|
ns |
namespace function |
iCol |
|
canEditRow |
can be either of the following:
|
canDeleteRow |
can be either of the following:
|
statusCol |
|
df with extra column containing buttons
Jasper Schelfhout
Start a transaction for a tibble
beginTransaction(tbl)
beginTransaction(tbl)
tbl |
|
Jasper Schelfhout
Re-usable documentation
canXXXRowTemplate(canEditRow, canDeleteRow)
canXXXRowTemplate(canEditRow, canDeleteRow)
canEditRow |
can be either of the following:
|
canDeleteRow |
can be either of the following:
|
data.frame
to editable types in datatableCast columns in data.frame
to editable types in datatable
castForDisplay(data, cols = colnames(data))
castForDisplay(data, cols = colnames(data))
data |
|
cols |
|
data.frame
with some columns cast to another type
Jasper Schelfhout
Cast tbl to class of template
castFromTbl(tbl, template)
castFromTbl(tbl, template)
tbl |
|
template |
tabular object like |
tbl cast to the type of template
Jasper Schelfhout
Cast all columns that exist in a foreignTbl to factor
castToFactor(data, foreignTbls)
castToFactor(data, foreignTbls)
data |
|
foreignTbls |
list of foreign tbls as created by |
Can be used to fixate possible options when editing.
data.frame
Jasper Schelfhout
Cast the data type to something supported by SQL.
castToSQLSupportedType(x)
castToSQLSupportedType(x)
x |
single value or vector of values |
x, possibly cast to different type
Jasper Schelfhout
Cast data to tbl
castToTbl(data)
castToTbl(data)
data |
object |
tbl
Jasper Schelfhout
tbl
or data.frame
x to the types of the templateCast tbl
or data.frame
x to the types of the template
castToTemplate(x, template)
castToTemplate(x, template)
x |
|
template |
|
If template is a tbl
with database source, convert to an in-memory tibble with same data types instead.
Rownames might differ or get lost.
object containing data of x in the class and structure of the template.
Jasper Schelfhout
foreignTbl
constraintsCheck if all rows in tbl fufill foreignTbl
constraints
checkForeignTbls(tbl, foreignTbls)
checkForeignTbls(tbl, foreignTbls)
tbl |
|
foreignTbls |
list of foreign tbls as created by |
logical
stating if tbl fufills all constraints imposed by all foreign tbls.
Jasper Schelfhout
NULL
argumentReturn first non NULL
argument
coalesce(...)
coalesce(...)
... |
set of arguments |
Jasper Schelfhout
Cast columns to the type of the template
coerceColumns(template, x)
coerceColumns(template, x)
template |
|
x |
|
only affects columns in both the template and x
DT::coerceValue
with better POSIXct
supportDT::coerceValue
with better POSIXct
support
coerceValue(val, old)
coerceValue(val, old)
val |
A character string. |
old |
An old value, whose type is the target type of |
Will assume UTC in case no timezone is specified.
Jasper Schelfhout
Start a transaction for a tibble
commitTransaction(tbl)
commitTransaction(tbl)
tbl |
|
Jasper Schelfhout
Connect to a database.
connectDB( dbname = system.file("extdata", "chinook.sqlite", package = utils::packageName()), drv = RSQLite::SQLite(), ... )
connectDB( dbname = system.file("extdata", "chinook.sqlite", package = utils::packageName()), drv = RSQLite::SQLite(), ... )
dbname |
|
drv |
database driver |
... |
arguments passed to |
Connects by default to a test SQLite database originally obtained here: chinook_git
database connection
conn <- connectDB() DBI::dbDisconnect(conn)
conn <- connectDB() DBI::dbDisconnect(conn)
Create buttons to modify the row.
createButtons( row, suffix, ns, canEditRow = TRUE, canDeleteRow = TRUE, statusCol = "status" )
createButtons( row, suffix, ns, canEditRow = TRUE, canDeleteRow = TRUE, statusCol = "status" )
row |
|
suffix |
|
ns |
|
canEditRow |
can be either of the following:
|
canDeleteRow |
can be either of the following:
|
statusCol |
|
buttons used per row in the app.
character(1)
HTML
Generate HTML for an in-row delete button
createDeleteButtonHTML(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
createDeleteButtonHTML(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
ns |
|
suffix |
|
disabled |
|
character(1)
HTML
Helper function to write HTML
createDeleteButtonHTML_shiny(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
createDeleteButtonHTML_shiny(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
ns |
|
suffix |
|
disabled |
|
only to be used interactively. sprintf() implementation is faster.
createEditButtonHTML
Generate HTML for an in-row edit button
createEditButtonHTML(ns, suffix, disabled = FALSE)
createEditButtonHTML(ns, suffix, disabled = FALSE)
ns |
|
suffix |
|
disabled |
|
character(1)
HTML
Helper function to write HTML
createEditButtonHTML_shiny(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
createEditButtonHTML_shiny(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
ns |
|
suffix |
|
disabled |
|
only to be used interactively. sprintf() implementation is faster.
createEditButtonHTML
eDT
Generate a custom button for eDT
customButton(id, label, icon = "", disabled = FALSE)
customButton(id, label, icon = "", disabled = FALSE)
id |
|
label |
|
icon |
|
disabled |
|
Combines elements of shiny::actionButton
and datatable options
list to be used in eDT(options = list(buttons = xxx))
Jasper Schelfhout
if(interactive()){ ui <- eDTOutput("data") server <- function(input,output,session){ b <- customButton('print', label = 'print') eDT_result <- eDT(id = "data", mtcars, options = list(buttons = list("save", b))) observeEvent(input$print,{ print(eDT_result$state()) }) } shinyApp(ui,server) }
if(interactive()){ ui <- eDTOutput("data") server <- function(input,output,session){ b <- customButton('print', label = 'print') eDT_result <- eDT(id = "data", mtcars, options = list(buttons = list("save", b))) observeEvent(input$print,{ print(eDT_result$state()) }) } shinyApp(ui,server) }
Server of the mtcars demo app
demoServer_custom(id, x)
demoServer_custom(id, x)
id |
|
x |
|
NULL, just executes the module server.
Jasper Schelfhout
Server of the DB demo app
demoServer_DB(id, conn)
demoServer_DB(id, conn)
id |
|
conn |
database connection object as given by |
NULL, just executes the module server.
Jasper Schelfhout
Server of the mtcars demo app
demoServer_mtcars(id)
demoServer_mtcars(id)
id |
|
NULL, just executes the module server.
Jasper Schelfhout
UI of the demo mtcars app
demoUI_custom(id)
demoUI_custom(id)
id |
|
HTML
Jasper Schelfhout
UI of the DB demo app
demoUI_DB(id, conn)
demoUI_DB(id, conn)
id |
|
conn |
database connection object as given by |
HTML
Jasper Schelfhout
UI of the demo mtcars app
demoUI_mtcars(id)
demoUI_mtcars(id)
id |
|
HTML
Jasper Schelfhout
Server of the development app
devServer(id, conn)
devServer(id, conn)
id |
|
conn |
database connection object as given by |
NULL, just executes the module server.
Jasper Schelfhout
UI of the development app
devUI(id, conn)
devUI(id, conn)
id |
|
conn |
database connection object as given by |
HTML
Jasper Schelfhout
Function to generate CSS to disable clicking events on a column
disableDoubleClickButtonCss(id)
disableDoubleClickButtonCss(id)
id |
|
https://stackoverflow.com/questions/75406546/apply-css-styling-to-a-single-dt-datatable
character
CSS
Insert rows into a tibble
e_rows_insert( x, y, by = NULL, ..., conflict = c("error", "ignore"), copy = FALSE, in_place = FALSE )
e_rows_insert( x, y, by = NULL, ..., conflict = c("error", "ignore"), copy = FALSE, in_place = FALSE )
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
... |
Other parameters passed onto methods. |
conflict |
For One of:
|
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_insert
.
Allows for specific implementations should the behavior differ from what's needed by editbl
.
Reason for separate method is to avoid conflicts on package loading.
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
Insert rows into a tibble
## Default S3 method: e_rows_insert( x, y, by = NULL, ..., conflict = c("error", "ignore"), copy = FALSE, in_place = FALSE )
## Default S3 method: e_rows_insert( x, y, by = NULL, ..., conflict = c("error", "ignore"), copy = FALSE, in_place = FALSE )
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
... |
Other parameters passed onto methods. |
conflict |
For One of:
|
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_insert
.
Allows for specific implementations should the behavior differ from what's needed by editbl
.
Reason for separate method is to avoid conflicts on package loading.
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
data.table
backends.rows_insert implementation for data.table
backends.
## S3 method for class 'dtplyr_step' e_rows_insert(x, y, by = NULL, ..., copy = FALSE, in_place = FALSE)
## S3 method for class 'dtplyr_step' e_rows_insert(x, y, by = NULL, ..., copy = FALSE, in_place = FALSE)
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
... |
Other parameters passed onto methods. |
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_insert
.
Allows for specific implementations should the behavior differ from what's needed by editbl
.
Reason for separate method is to avoid conflicts on package loading.
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
Jasper Schelfhout
rows_insert implementation for DBI backends.
## S3 method for class 'tbl_dbi' e_rows_insert(x, y, by = NULL, ..., copy = FALSE, in_place = FALSE)
## S3 method for class 'tbl_dbi' e_rows_insert(x, y, by = NULL, ..., copy = FALSE, in_place = FALSE)
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
... |
Other parameters passed onto methods. |
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_insert
.
Allows for specific implementations should the behavior differ from what's needed by editbl
.
Reason for separate method is to avoid conflicts on package loading.
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
Jasper Schelfhout
library(dplyr) # Set up a test table conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") artists_df <- data.frame( ArtistId = c(1,2), Name = c("AC/DC", "The Offspring") ) DBI::dbWriteTable(conn, "Artist", artists_df) # Insert new row artists <- tbl(conn, "Artist") DBI::dbBegin(conn) e_rows_insert(artists, data.frame(ArtistId = 999, Name = "testArtist"), in_place = TRUE) DBI::dbRollback(conn) DBI::dbDisconnect(conn)
library(dplyr) # Set up a test table conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") artists_df <- data.frame( ArtistId = c(1,2), Name = c("AC/DC", "The Offspring") ) DBI::dbWriteTable(conn, "Artist", artists_df) # Insert new row artists <- tbl(conn, "Artist") DBI::dbBegin(conn) e_rows_insert(artists, data.frame(ArtistId = 999, Name = "testArtist"), in_place = TRUE) DBI::dbRollback(conn) DBI::dbDisconnect(conn)
Update rows of a tibble
e_rows_update( x, y, by = NULL, ..., match, unmatched = c("error", "ignore"), copy = FALSE, in_place = FALSE )
e_rows_update( x, y, by = NULL, ..., match, unmatched = c("error", "ignore"), copy = FALSE, in_place = FALSE )
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
... |
Other parameters passed onto methods. |
match |
named |
unmatched |
For One of:
|
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_update
.
Allows for specific implementations should the behavior differ from what's needed by editbl
.
Reason for separate method is to avoid conflicts on package loading.
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
rows_update implementation for data.frame backends.
## S3 method for class 'data.frame' e_rows_update( x, y, by = NULL, match = NULL, ..., copy = FALSE, in_place = FALSE )
## S3 method for class 'data.frame' e_rows_update( x, y, by = NULL, match = NULL, ..., copy = FALSE, in_place = FALSE )
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
match |
named |
... |
Other parameters passed onto methods. |
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_update
.
Allows for specific implementations should the behavior differ from what's needed by editbl
.
Reason for separate method is to avoid conflicts on package loading.
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
Jasper Schelfhout
Update rows of a tibble
## Default S3 method: e_rows_update( x, y, by = NULL, ..., match = match, unmatched = c("error", "ignore"), copy = FALSE, in_place = FALSE )
## Default S3 method: e_rows_update( x, y, by = NULL, ..., match = match, unmatched = c("error", "ignore"), copy = FALSE, in_place = FALSE )
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
... |
Other parameters passed onto methods. |
match |
named |
unmatched |
For One of:
|
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_update
.
Allows for specific implementations should the behavior differ from what's needed by editbl
.
Reason for separate method is to avoid conflicts on package loading.
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
rows_update implementation for data.table backends.
## S3 method for class 'dtplyr_step' e_rows_update( x, y, by = NULL, match = NULL, ..., copy = FALSE, in_place = FALSE )
## S3 method for class 'dtplyr_step' e_rows_update( x, y, by = NULL, match = NULL, ..., copy = FALSE, in_place = FALSE )
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
match |
named |
... |
Other parameters passed onto methods. |
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_update
.
Allows for specific implementations should the behavior differ from what's needed by editbl
.
Reason for separate method is to avoid conflicts on package loading.
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
Jasper Schelfhout
rows_update implementation for DBI backends.
## S3 method for class 'tbl_dbi' e_rows_update( x, y, by = NULL, match = NULL, ..., copy = FALSE, in_place = FALSE )
## S3 method for class 'tbl_dbi' e_rows_update( x, y, by = NULL, match = NULL, ..., copy = FALSE, in_place = FALSE )
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
match |
named |
... |
Other parameters passed onto methods. |
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_update
.
Allows for specific implementations should the behavior differ from what's needed by editbl
.
Reason for separate method is to avoid conflicts on package loading.
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
Jasper Schelfhout
library(dplyr) # Set up a test table conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") artists_df <- data.frame( ArtistId = c(1,2), Name = c("AC/DC", "The Offspring") ) DBI::dbWriteTable(conn, "Artist", artists_df) # Update rows without changing the key. artists <- tbl(conn, "Artist") DBI::dbBegin(conn) y <- data.frame(ArtistId = 1, Name = "DC/AC") e_rows_update( x = artists, y = y, by = "ArtistId", in_place = TRUE) DBI::dbRollback(conn) # Update key values of rows. DBI::dbBegin(conn) y <- data.frame(ArtistId = 999, Name = "DC/AC") match <- list( x = data.frame("ArtistId" = 1), y = data.frame("ArtistId" = 999) ) e_rows_update( x = artists, y = y, match = match, by = "ArtistId", in_place = TRUE) DBI::dbRollback(conn) DBI::dbDisconnect(conn)
library(dplyr) # Set up a test table conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") artists_df <- data.frame( ArtistId = c(1,2), Name = c("AC/DC", "The Offspring") ) DBI::dbWriteTable(conn, "Artist", artists_df) # Update rows without changing the key. artists <- tbl(conn, "Artist") DBI::dbBegin(conn) y <- data.frame(ArtistId = 1, Name = "DC/AC") e_rows_update( x = artists, y = y, by = "ArtistId", in_place = TRUE) DBI::dbRollback(conn) # Update key values of rows. DBI::dbBegin(conn) y <- data.frame(ArtistId = 999, Name = "DC/AC") match <- list( x = data.frame("ArtistId" = 1), y = data.frame("ArtistId" = 999) ) e_rows_update( x = artists, y = y, match = match, by = "ArtistId", in_place = TRUE) DBI::dbRollback(conn) DBI::dbDisconnect(conn)
Create a modifieable datatable.
eDT( data, options = list(dom = "Bfrtlip", keys = TRUE, ordering = FALSE, autoFill = list(update = FALSE, focus = "focus"), buttons = list("add", "undo", "redo", "save")), class = "display", callback = NULL, rownames = FALSE, colnames = NULL, container, caption = NULL, filter = c("none", "bottom", "top"), escape = TRUE, style = "auto", width = NULL, height = NULL, elementId = NULL, fillContainer = getOption("DT.fillContainer", NULL), autoHideNavigation = getOption("DT.autoHideNavigation", NULL), selection = "none", extensions = c("KeyTable", "AutoFill", "Buttons"), plugins = NULL, editable = list(target = "cell"), id, keys = NULL, in_place = FALSE, format = function(x) { x }, foreignTbls = list(), statusColor = c(insert = "#e6e6e6", update = "#32a6d3", delete = "#e52323"), inputUI = editbl::inputUI, defaults = tibble(), env = environment(), canEditRow = TRUE, canDeleteRow = TRUE, utilityColumns = NULL )
eDT( data, options = list(dom = "Bfrtlip", keys = TRUE, ordering = FALSE, autoFill = list(update = FALSE, focus = "focus"), buttons = list("add", "undo", "redo", "save")), class = "display", callback = NULL, rownames = FALSE, colnames = NULL, container, caption = NULL, filter = c("none", "bottom", "top"), escape = TRUE, style = "auto", width = NULL, height = NULL, elementId = NULL, fillContainer = getOption("DT.fillContainer", NULL), autoHideNavigation = getOption("DT.autoHideNavigation", NULL), selection = "none", extensions = c("KeyTable", "AutoFill", "Buttons"), plugins = NULL, editable = list(target = "cell"), id, keys = NULL, in_place = FALSE, format = function(x) { x }, foreignTbls = list(), statusColor = c(insert = "#e6e6e6", update = "#32a6d3", delete = "#e52323"), inputUI = editbl::inputUI, defaults = tibble(), env = environment(), canEditRow = TRUE, canDeleteRow = TRUE, utilityColumns = NULL )
data |
|
options |
a list of initialization options (see
https://datatables.net/reference/option/); the character options
wrapped in |
class |
the CSS class(es) of the table; see https://datatables.net/manual/styling/classes |
callback |
the body of a JavaScript callback function with the argument
|
rownames |
|
colnames |
if missing, the column names of the data; otherwise it can be
an unnamed character vector of names you want to show in the table header
instead of the default data column names; alternatively, you can provide a
named numeric or character vector of the form |
container |
a sketch of the HTML table to be filled with data cells; by
default, it is generated from |
caption |
the table caption; a character vector or a tag object
generated from |
filter |
whether/where to use column filters; |
escape |
whether to escape HTML entities in the table: |
style |
either |
width , height
|
Width/Height in pixels (optional, defaults to automatic sizing) |
elementId |
An id for the widget (a random string by default). |
fillContainer |
|
autoHideNavigation |
|
selection |
the row/column selection mode (single or multiple selection
or disable selection) when a table widget is rendered in a Shiny app;
alternatively, you can use a list of the form |
extensions |
a character vector of the names of the DataTables extensions (https://datatables.net/extensions/index) |
plugins |
a character vector of the names of DataTables plug-ins
(https://rstudio.github.io/DT/plugins.html). Note that only those
plugins supported by the |
editable |
|
id |
|
keys |
|
in_place |
|
format |
function accepting and returning a |
foreignTbls |
|
statusColor |
named |
inputUI |
|
defaults |
expression that evaluates to a |
env |
|
canEditRow |
can be either of the following:
|
canDeleteRow |
can be either of the following:
|
utilityColumns |
named character vector. Defines names for (hidden) utility columns
used by c( status = '_editbl_status', buttons = '_editbl_buttons', identity = '_editbl_identity', deleted = '_editbl_deleted' ) |
Works the same as datatable
.
This function is however a shiny module and comes with additional arguments and different defaults.
Instead of having output$id = renderDT(DT::datatable(iris))
, eDT(id = 'id', data = iris)
should be used on the server side.
On the UI side eDTOutput
should be used instead of DTOutput
.
Can also be used as standalone app when not ran in reactive context.
All arguments except 'id' and 'env' can be normal objects or reactive objects.
list
result reactive
modified version of data
(saved)
state reactive
current state of the data
(unsaved)
selected reactive
selected rows of the data
(unsaved)
Jasper Schelfhout
## Only run this example in interactive R sessions if(interactive()){ # tibble support modifiedData <- editbl::eDT(tibble::as_tibble(mtcars)) # data.table support modifiedData <- editbl::eDT(dtplyr::lazy_dt(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) # Within shiny library(shiny) library(editbl) shinyApp( ui = fluidPage(fluidRow(column(12, eDTOutput('tbl')))), server = function(input, output) { eDT('tbl',iris,) } ) # Custom inputUI editbl::eDT(mtcars, inputUI = function(id, data){ ns <- NS(id) textInput( ns("mpg"), label = "mpg", value = data$mpg)}) # Do not allow delete editbl::eDT(mtcars, canDeleteRow = FALSE) }
## Only run this example in interactive R sessions if(interactive()){ # tibble support modifiedData <- editbl::eDT(tibble::as_tibble(mtcars)) # data.table support modifiedData <- editbl::eDT(dtplyr::lazy_dt(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) # Within shiny library(shiny) library(editbl) shinyApp( ui = fluidPage(fluidRow(column(12, eDTOutput('tbl')))), server = function(input, output) { eDT('tbl',iris,) } ) # Custom inputUI editbl::eDT(mtcars, inputUI = function(id, data){ ns <- NS(id) textInput( ns("mpg"), label = "mpg", value = data$mpg)}) # Do not allow delete editbl::eDT(mtcars, canDeleteRow = FALSE) }
Open interactive app to explore and modify data
eDT_app(...)
eDT_app(...)
... |
arguments past to |
When eDT
is not used within the server of a shiny app, it will
call this function to start up a shiny app itself. Just as DT::datatable()
displays a table
in the browser when called upon interactively.
data (or a modified version thereof) once you click 'close'
Server of eDT_app
eDT_app_server(moduleId = "nevergonnagiveyouup", ...)
eDT_app_server(moduleId = "nevergonnagiveyouup", ...)
moduleId |
|
... |
arguments passed to eDT |
moduleServer which on application stop returns version of x with made changes
Jasper Schelfhout
UI of eDT_app
eDT_app_ui(moduleId = "nevergonnagiveyouup", eDTId = "nevergonnaletyoudown")
eDT_app_ui(moduleId = "nevergonnagiveyouup", eDTId = "nevergonnaletyoudown")
moduleId |
|
eDTId |
|
HTML
Jasper Schelfhout
eDT
UI part of eDT
eDTOutput(id, ...)
eDTOutput(id, ...)
id |
|
... |
arguments passed to |
Works exactly like DTOutput
apart from the fact that instead of the outputId
argument, id
is requested. Reason being that this function is a UI to a shiny module.
This means that the datatable can be found under the id '{namespace}-{id}-DT'
instead of '{namespace}-{outputId}'
.
Also some minor CSS and javascript is executed for functional puposes.
HTML
Jasper Schelfhout
## Only run this example in interactive R sessions if(interactive()){ # tibble support modifiedData <- editbl::eDT(tibble::as_tibble(mtcars)) # data.table support modifiedData <- editbl::eDT(dtplyr::lazy_dt(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) # Within shiny library(shiny) library(editbl) shinyApp( ui = fluidPage(fluidRow(column(12, eDTOutput('tbl')))), server = function(input, output) { eDT('tbl',iris,) } ) # Custom inputUI editbl::eDT(mtcars, inputUI = function(id, data){ ns <- NS(id) textInput( ns("mpg"), label = "mpg", value = data$mpg)}) # Do not allow delete editbl::eDT(mtcars, canDeleteRow = FALSE) }
## Only run this example in interactive R sessions if(interactive()){ # tibble support modifiedData <- editbl::eDT(tibble::as_tibble(mtcars)) # data.table support modifiedData <- editbl::eDT(dtplyr::lazy_dt(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) # Within shiny library(shiny) library(editbl) shinyApp( ui = fluidPage(fluidRow(column(12, eDTOutput('tbl')))), server = function(input, output) { eDT('tbl',iris,) } ) # Custom inputUI editbl::eDT(mtcars, inputUI = function(id, data){ ns <- NS(id) textInput( ns("mpg"), label = "mpg", value = data$mpg)}) # Do not allow delete editbl::eDT(mtcars, canDeleteRow = FALSE) }
Determine if a row can be deleted
evalCanDeleteRow(row, canDeleteRow = TRUE, statusCol = "status")
evalCanDeleteRow(row, canDeleteRow = TRUE, statusCol = "status")
row |
|
canDeleteRow |
|
statusCol |
|
calling this around the user passed on function ensures that newly inserted rows are being excempt from the logic. Moreover, the output of the function can be checked.
boolean
Jasper Schelfhout
Determine if a row can be edited
evalCanEditRow(row, canEditRow = TRUE, statusCol = "status")
evalCanEditRow(row, canEditRow = TRUE, statusCol = "status")
row |
|
canEditRow |
|
statusCol |
|
calling this around the user passed on function ensures that newly inserted rows are being excempt from the logic. Moreover, the output of the function can be checked.
boolean
Jasper Schelfhout
Fill data columns based on foreignTbls
fillDeductedColumns(tbl, foreignTbls)
fillDeductedColumns(tbl, foreignTbls)
tbl |
|
foreignTbls |
list of foreign tbls as created by |
When a combination of columns is not found in the foreignTbl, fill the deductedColumns with NA.
on foreignTbls suggesting conflicting data, an arbitrary choice is made. It is best to afterwards check with checkForeignTbls to see if a valid result is obtained.
tbl
Jasper Schelfhout
Replace instances of integer64 with actual NA values instead of weird default 9218868437227407266
fixInteger64(x)
fixInteger64(x)
x |
|
x with integer64
columns set to bit64::as.integer64(NA)
Jasper Schelfhout
Create a foreign tibble
foreignTbl( x, y, by = intersect(dplyr::tbl_vars(x), dplyr::tbl_vars(y)), naturalKey = dplyr::tbl_vars(y), allowNew = FALSE )
foreignTbl( x, y, by = intersect(dplyr::tbl_vars(x), dplyr::tbl_vars(y)), naturalKey = dplyr::tbl_vars(y), allowNew = FALSE )
x |
|
y |
|
by |
|
naturalKey |
|
allowNew |
|
This is a tibble that can be passed onto eDT
as a referenced table.
It is the equivalent of a database table to which the data
tbl of eDT has a foreign key.
It will be merged with the tbl passed onto the data
argument allowing to provide restrictions
for certain columns.
Note that row uniqueness for the columns used in by
and naturalKey
is assumed.
This assumption will however not be checked since it is an expensive operation on big datasets.
However, if violated, it might give errors or unexpected results during usage of the eDT module.
List with unmodified arguments. However, they have now been checked for validity.
y, see argument y
.
by, see argument by
.
naturalKey, see argument naturalKey
.
allowNew, see argument allowNew
Jasper Schelfhout
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" ) ## Only run this in interactive R sessions if(interactive()){ eDT(a, foreignTbls = list(b), options = list(columnDefs = list(list(visible=FALSE, targets="last_name_id"))) ) }
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" ) ## Only run this in interactive R sessions if(interactive()){ eDT(a, foreignTbls = list(b), options = list(columnDefs = list(list(visible=FALSE, targets="last_name_id"))) ) }
Get name of the tbl in the database
get_db_table_name(x)
get_db_table_name(x)
x |
|
SQL, the table name as used in the database
Get types of columns in a tbl
getColumnTypeSums(tbl)
getColumnTypeSums(tbl)
tbl |
|
named list with types of the colums
Jasper Schelfhout
Get all columns that are not natural keys
getNonNaturalKeyCols(foreignTbls)
getNonNaturalKeyCols(foreignTbls)
foreignTbls |
list of foreign tbls as created by |
character
Jasper Schelfhout
Add some extra columns to data to allow for / keep track of modifications
initData( data, ns, buttonCol = "buttons", statusCol = "status", deleteCol = "deleted", iCol = "i", canDeleteRow = TRUE, canEditRow = TRUE )
initData( data, ns, buttonCol = "buttons", statusCol = "status", deleteCol = "deleted", iCol = "i", canDeleteRow = TRUE, canEditRow = TRUE )
data |
|
ns |
namespace function |
buttonCol |
|
statusCol |
|
deleteCol |
|
iCol |
|
canDeleteRow |
can be either of the following:
|
canEditRow |
can be either of the following:
|
data with extra columns buttons, status, i.
Jasper Schelfhout
data.frame
An input server for a data.frame
inputServer(id, data, ...)
inputServer(id, data, ...)
id |
|
data |
single row |
... |
further arguments for methods |
A new method for this can be added if you wish to alter the default behavior of the pop-up modals in eDT
.
modified version of data
Jasper Schelfhout
if(interactive()){ library(shiny) ui <- inputUI('id') server <- function(input,output,session){ input <- inputServer("id", mtcars[1,]) observe({print(input())}) } shinyApp(ui, server) }
if(interactive()){ library(shiny) ui <- inputUI('id') server <- function(input,output,session){ input <- inputServer("id", mtcars[1,]) observe({print(input())}) } shinyApp(ui, server) }
data.frame
An input server for a data.frame
## Default S3 method: inputServer(id, data, colnames, notEditable, foreignTbls, ...)
## Default S3 method: inputServer(id, data, colnames, notEditable, foreignTbls, ...)
id |
|
data |
single row |
colnames |
named |
notEditable |
|
foreignTbls |
list of foreignTbls. See |
... |
for compatibility with other methods |
Reads all inputs ids that are identical to column names of the data and updates the data.
reactive modified version of data
Jasper Schelfhout
data.frame
An input UI for a data.frame
inputUI(id, ...)
inputUI(id, ...)
id |
|
... |
arguments passed onto methods |
A new method for this can be added if you wish to alter the default behavior of the pop-up modals in eDT
.
HTML. A set of input fields corresponding to the given row.
Jasper Schelfhout
if(interactive()){ library(shiny) ui <- inputUI('id') server <- function(input,output,session){ input <- inputServer("id", mtcars[1,]) observe({print(input())}) } shinyApp(ui, server) }
if(interactive()){ library(shiny) ui <- inputUI('id') server <- function(input,output,session){ input <- inputServer("id", mtcars[1,]) observe({print(input())}) } shinyApp(ui, server) }
UI part for modal with input fields for editing
## Default S3 method: inputUI(id, ...)
## Default S3 method: inputUI(id, ...)
id |
character module id |
... |
for compatibility with method |
The UI elements that have an id identical to a column name are used for updating the data.
HTML. A set of input fields corresponding to the given row.
Jasper Schelfhout
Merge a tbl with it a foreignTbl
joinForeignTbl( tbl, foreignTbl, keepNA = TRUE, by = foreignTbl$by, copy = TRUE, type = c("inner", "left")[1] )
joinForeignTbl( tbl, foreignTbl, keepNA = TRUE, by = foreignTbl$by, copy = TRUE, type = c("inner", "left")[1] )
tbl |
|
foreignTbl |
|
keepNA |
|
by |
named |
copy |
|
type |
|
see also dplyr
join functions, for example dplyr::left_join
.
tbl
, containing both columns from argument tbl
and argument foreignTbl
.
Jasper Schelfhout
Overwrite default settings with provided settings
overwriteDefaults(defaults, settings)
overwriteDefaults(defaults, settings)
defaults |
named character vector |
settings |
named character vector |
named character vector
Jasper Schelfhout
Start a transaction for a tibble
rollbackTransaction(tbl)
rollbackTransaction(tbl)
tbl |
|
Jasper Schelfhout
Add a row to a table in the database.
rowInsert(conn, table, values)
rowInsert(conn, table, values)
conn |
database connection object as given by |
table |
character |
values |
named list, row to add. Names are database column names. Unspecified columns will get database defaults. |
integer number of affected rows.
rows_delete implementation for data.table backends.
## S3 method for class 'dtplyr_step' rows_delete(x, y, by = NULL, ..., unmatched, copy = FALSE, in_place = FALSE)
## S3 method for class 'dtplyr_step' rows_delete(x, y, by = NULL, ..., unmatched, copy = FALSE, in_place = FALSE)
x , y
|
A pair of data frames or data frame extensions (e.g. a tibble).
|
by |
An unnamed character vector giving the key columns. The key columns
must exist in both By default, we use the first column in |
... |
Other parameters passed onto methods. |
unmatched |
For One of:
|
copy |
If |
in_place |
Should When |
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
rows_update()
and rows_patch()
preserve the number of rows;
rows_insert()
, rows_append()
, and rows_upsert()
return all existing
rows and potentially new rows; rows_delete()
returns a subset of the
rows.
Columns are not added, removed, or relocated, though the data may be updated.
Groups are taken from x
.
Data frame attributes are taken from x
.
If in_place = TRUE
, the result will be returned invisibly.
Jasper Schelfhout
Update rows in the database.
rowUpdate(conn, table, values, where)
rowUpdate(conn, table, values, where)
conn |
database connection object as given by |
table |
character |
values |
named list, values to be set. Names are database column names. |
where |
named list, values to filter on. Names are database column names. If NULL no filter is applied. |
integer number of affected rows.
Run a demo app
runDemoApp(app = "database", ...)
runDemoApp(app = "database", ...)
app |
demoApp to run. Options: database / mtcars / custom |
... |
arguments passed onto the demoApp |
These apps are for illustrative purposes.
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
## Only run this example in interactive R sessions if(interactive()){ # Database tmpFile <- tempfile(fileext = ".sqlite") file.copy(system.file("extdata", "chinook.sqlite", package = 'editbl'), tmpFile) conn <- connectDB(dbname = tmpFile) runDemoApp(app = "database", conn = conn) DBI::dbDisconnect(conn) unlink(tmpFile) # mtcars runDemoApp(app = "mtcars") # Any tibble of your liking runDemoApp(app = "custom", dplyr::tibble(iris)) }
## Only run this example in interactive R sessions if(interactive()){ # Database tmpFile <- tempfile(fileext = ".sqlite") file.copy(system.file("extdata", "chinook.sqlite", package = 'editbl'), tmpFile) conn <- connectDB(dbname = tmpFile) runDemoApp(app = "database", conn = conn) DBI::dbDisconnect(conn) unlink(tmpFile) # mtcars runDemoApp(app = "mtcars") # Any tibble of your liking runDemoApp(app = "custom", dplyr::tibble(iris)) }
Run a custom demo app
runDemoApp_custom(x)
runDemoApp_custom(x)
x |
|
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
Run a demo app
runDemoApp_DB()
runDemoApp_DB()
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
Run a demo app
runDemoApp_mtcars()
runDemoApp_mtcars()
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
Run a development app
runDevApp()
runDevApp()
This app prints some of the server objects and has a button to interactively browse the code. This is useful for debugging and experimenting with new features.
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
datatable
as select inputServer part to use a datatable
as select input
selectInputDT_Server( id, label = "", choices, selected = NULL, multiple = FALSE )
selectInputDT_Server( id, label = "", choices, selected = NULL, multiple = FALSE )
id |
|
label |
|
choices |
|
selected |
|
multiple |
|
A selection of rows from the data.frame
provided under choices.
Jasper Schelfhout
shiny::selectInput
. This function can be more convenient for selecting rows
with multiple columns.
## Only run this example in interactive R sessions if(interactive()){ ui <- selectInputDT_UI('id') data <- data.frame(id = 1:3, name = letters[1:3]) server <- function(input,output, session){ selected = selectInputDT_Server('id', choices = data, selected = data[1,] ) observe({print(selected())}) } shiny::shinyApp(ui, server) }
## Only run this example in interactive R sessions if(interactive()){ ui <- selectInputDT_UI('id') data <- data.frame(id = 1:3, name = letters[1:3]) server <- function(input,output, session){ selected = selectInputDT_Server('id', choices = data, selected = data[1,] ) observe({print(selected())}) } shiny::shinyApp(ui, server) }
UI part of a DT select input
selectInputDT_UI(id)
selectInputDT_UI(id)
id |
|
HTML
Jasper Schelfhout
## Only run this example in interactive R sessions if(interactive()){ ui <- selectInputDT_UI('id') data <- data.frame(id = 1:3, name = letters[1:3]) server <- function(input,output, session){ selected = selectInputDT_Server('id', choices = data, selected = data[1,] ) observe({print(selected())}) } shiny::shinyApp(ui, server) }
## Only run this example in interactive R sessions if(interactive()){ ui <- selectInputDT_UI('id') data <- data.frame(id = 1:3, name = letters[1:3]) server <- function(input,output, session){ selected = selectInputDT_Server('id', choices = data, selected = data[1,] ) observe({print(selected())}) } shiny::shinyApp(ui, server) }
tbl
Get a shiny input for a column of a tbl
shinyInput(x, inputId, label, selected)
shinyInput(x, inputId, label, selected)
x |
column |
inputId |
shiny input Id |
label |
|
selected |
object of class of x |
shiny input
Jasper Schelfhout
Standardize colnames argument to the format of named character vector
standardizeArgument_colnames(colnames, data)
standardizeArgument_colnames(colnames, data)
colnames |
if missing, the column names of the data; otherwise it can be
an unnamed character vector of names you want to show in the table header
instead of the default data column names; alternatively, you can provide a
named numeric or character vector of the form |
data |
|
named character vector
Jasper Schelfhout
Standardized editable argument to be in the form of a list
standardizeArgument_editable(editable, data)
standardizeArgument_editable(editable, data)
editable |
|
data |
|
list of the form list(target = foo, ...)
Jasper Schelfhout
Generate where sql
whereSQL(conn, table, column, operator = "in", values = NULL)
whereSQL(conn, table, column, operator = "in", values = NULL)
conn |
database connection object as given by |
table |
character table name (or alias used in query) |
column |
character column of table |
operator |
character |
values |
character vector of values |
character sql
Jasper Schelfhout