Type: | Package |
Version: | 1.3.0 |
Date: | 2025-04-23 |
Title: | 'DT' Extension for CRUD (Create, Read, Update, Delete) Applications in 'shiny' |
Maintainer: | Jasper Schelfhout <jasper.schelfhout@openanalytics.eu> |
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. |
License: | GPL-3 |
Copyright: | Open Analytics NV, 2023 |
Imports: | shiny, shinyjs, DT, tibble, dplyr, rlang, uuid, fontawesome (≥ 0.4.0) |
Suggests: | testthat, dtplyr, data.table, vctrs, RSQLite, dbplyr, glue, DBI, bit64, knitr, dm |
URL: | https://github.com/openanalytics/editbl |
BugReports: | https://github.com/openanalytics/editbl/issues |
VignetteBuilder: | knitr |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-04-24 13:12:08 UTC; jasper |
Author: | Jasper Schelfhout [aut, cre], Maxim Nazarov [rev], Daan Seynaeve [rev], Lennart Tuijnder [rev], Saar Junius [aut] |
Repository: | CRAN |
Date/Publication: | 2025-04-24 13:40:02 UTC |
Add modification buttons as a column
Description
Add modification buttons as a column
Usage
addButtons(
df,
columnName,
ns,
iCol = "i",
canEditRow = TRUE,
canDeleteRow = TRUE,
canCloneRow = TRUE,
statusCol = "_editbl_status"
)
Arguments
df |
|
columnName |
|
ns |
namespace function |
iCol |
|
canEditRow |
can be either of the following:
|
canDeleteRow |
can be either of the following:
|
canCloneRow |
can be either of the following:
|
statusCol |
|
Value
df with extra column containing buttons
Author(s)
Jasper Schelfhout
Start a transaction for a tibble
Description
Start a transaction for a tibble
Usage
beginTransaction(tbl)
Arguments
tbl |
|
Author(s)
Jasper Schelfhout
Re-usable documentation
Description
Re-usable documentation
Usage
canXXXRowTemplate(canEditRow, canCloneRow, canDeleteRow)
Arguments
canEditRow |
can be either of the following:
|
canCloneRow |
can be either of the following:
|
canDeleteRow |
can be either of the following:
|
Cast columns in data.frame
to editable types in datatable
Description
Cast columns in data.frame
to editable types in datatable
Usage
castForDisplay(data, cols = colnames(data))
Arguments
data |
|
cols |
|
Value
data.frame
with some columns cast to another type
Author(s)
Jasper Schelfhout
Cast tbl to class of template
Description
Cast tbl to class of template
Usage
castFromTbl(tbl, template)
Arguments
tbl |
|
template |
tabular object like |
Value
tbl cast to the type of template
Author(s)
Jasper Schelfhout
Cast all columns that exist in a foreignTbl to factor
Description
Cast all columns that exist in a foreignTbl to factor
Usage
castToFactor(data, foreignTbls)
Arguments
data |
|
foreignTbls |
list of foreign tbls as created by |
Details
Can be used to fixate possible options when editing.
Value
data.frame
Author(s)
Jasper Schelfhout
Cast the data type to something supported by SQL.
Description
Cast the data type to something supported by SQL.
Usage
castToSQLSupportedType(x)
Arguments
x |
single value or vector of values |
Value
x, possibly cast to different type
Author(s)
Jasper Schelfhout
Cast data to tbl
Description
Cast data to tbl
Usage
castToTbl(data)
Arguments
data |
object |
Value
tbl
Author(s)
Jasper Schelfhout
Cast tbl
or data.frame
x to the types of the template
Description
Cast tbl
or data.frame
x to the types of the template
Usage
castToTemplate(x, template)
Arguments
x |
|
template |
|
Details
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.
Value
object containing data of x in the class and structure of the template.
Author(s)
Jasper Schelfhout
Check if all rows in tbl fufill foreignTbl
constraints
Description
Check if all rows in tbl fufill foreignTbl
constraints
Usage
checkForeignTbls(tbl, foreignTbls)
Arguments
tbl |
|
foreignTbls |
list of foreign tbls as created by |
Value
logical
stating if tbl fufills all constraints imposed by all foreign tbls.
Author(s)
Jasper Schelfhout
Return first non NULL
argument
Description
Return first non NULL
argument
Usage
coalesce(...)
Arguments
... |
set of arguments |
Author(s)
Jasper Schelfhout
Cast columns to the type of the template
Description
Cast columns to the type of the template
Usage
coerceColumns(template, x)
Arguments
template |
|
x |
|
Details
only affects columns in both the template and x
DT::coerceValue
with better POSIXct
support
Description
DT::coerceValue
with better POSIXct
support
Usage
coerceValue(val, old)
Arguments
val |
A character string. |
old |
An old value, whose type is the target type of |
Details
Will assume UTC in case no timezone is specified.
Author(s)
Jasper Schelfhout
Start a transaction for a tibble
Description
Start a transaction for a tibble
Usage
commitTransaction(tbl)
Arguments
tbl |
|
Author(s)
Jasper Schelfhout
Connect to a database.
Description
Connect to a database.
Usage
connectDB(
dbname = system.file("extdata", "chinook.sqlite", package = utils::packageName()),
drv = RSQLite::SQLite(),
...
)
Arguments
dbname |
|
drv |
database driver |
... |
arguments passed to |
Details
Connects by default to a test SQLite database originally obtained here: chinook_git
Value
database connection
Examples
conn <- connectDB()
DBI::dbDisconnect(conn)
Create buttons to modify the row.
Description
Create buttons to modify the row.
Usage
createButtons(
row,
suffix,
ns,
canEditRow = TRUE,
canDeleteRow = TRUE,
canCloneRow = TRUE,
statusCol = "_editbl_status"
)
Arguments
row |
|
suffix |
|
ns |
|
canEditRow |
can be either of the following:
|
canDeleteRow |
can be either of the following:
|
canCloneRow |
can be either of the following:
|
statusCol |
|
Details
buttons used per row in the app.
Value
character(1)
HTML
Generate HTML for an in-row clone button
Description
Generate HTML for an in-row clone button
Usage
createCloneButtonHTML(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
Arguments
ns |
|
suffix |
|
disabled |
|
Value
character(1)
HTML
Helper function to write HTML
Description
Helper function to write HTML
Usage
createCloneButtonHTML_shiny(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
Arguments
ns |
|
suffix |
|
disabled |
|
Details
only to be used interactively. sprintf() implementation is faster.
See Also
createCloneButtonHTML
Generate HTML for an in-row delete button
Description
Generate HTML for an in-row delete button
Usage
createDeleteButtonHTML(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
Arguments
ns |
|
suffix |
|
disabled |
|
Value
character(1)
HTML
Helper function to write HTML
Description
Helper function to write HTML
Usage
createDeleteButtonHTML_shiny(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
Arguments
ns |
|
suffix |
|
disabled |
|
Details
only to be used interactively. sprintf() implementation is faster.
See Also
createEditButtonHTML
Generate HTML for an in-row edit button
Description
Generate HTML for an in-row edit button
Usage
createEditButtonHTML(ns, suffix, disabled = FALSE)
Arguments
ns |
|
suffix |
|
disabled |
|
Value
character(1)
HTML
Helper function to write HTML
Description
Helper function to write HTML
Usage
createEditButtonHTML_shiny(ns = "%1$s", suffix = "%2$s", disabled = FALSE)
Arguments
ns |
|
suffix |
|
disabled |
|
Details
only to be used interactively. sprintf() implementation is faster.
See Also
createEditButtonHTML
Generate a custom button for eDT
Description
Generate a custom button for eDT
Usage
customButton(id, label, icon = "", disabled = FALSE)
Arguments
id |
|
label |
|
icon |
|
disabled |
|
Details
Combines elements of shiny::actionButton
and datatable options
Value
list to be used in eDT(options = list(buttons = xxx))
Author(s)
Jasper Schelfhout
Examples
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 DB demo app
Description
Server of the DB demo app
Usage
demoServer_DB(id, conn)
Arguments
id |
|
conn |
database connection object as given by |
Value
NULL, just executes the module server.
Author(s)
Jasper Schelfhout
Server of the mtcars demo app
Description
Server of the mtcars demo app
Usage
demoServer_custom(id, x)
Arguments
id |
|
x |
|
Value
NULL, just executes the module server.
Author(s)
Jasper Schelfhout
Server of the mtcars demo app
Description
Server of the mtcars demo app
Usage
demoServer_mtcars(id)
Arguments
id |
|
Value
NULL, just executes the module server.
Author(s)
Jasper Schelfhout
UI of the DB demo app
Description
UI of the DB demo app
Usage
demoUI_DB(id, conn)
Arguments
id |
|
conn |
database connection object as given by |
Value
HTML
Author(s)
Jasper Schelfhout
UI of the demo mtcars app
Description
UI of the demo mtcars app
Usage
demoUI_custom(id)
Arguments
id |
|
Value
HTML
Author(s)
Jasper Schelfhout
UI of the demo mtcars app
Description
UI of the demo mtcars app
Usage
demoUI_mtcars(id)
Arguments
id |
|
Value
HTML
Author(s)
Jasper Schelfhout
Server of the development app
Description
Server of the development app
Usage
devServer(id, conn)
Arguments
id |
|
conn |
database connection object as given by |
Value
NULL, just executes the module server.
Author(s)
Jasper Schelfhout
UI of the development app
Description
UI of the development app
Usage
devUI(id, conn)
Arguments
id |
|
conn |
database connection object as given by |
Value
HTML
Author(s)
Jasper Schelfhout
Function to generate CSS to disable clicking events on a column
Description
Function to generate CSS to disable clicking events on a column
Usage
disableDoubleClickButtonCss(id)
Arguments
id |
|
Details
https://stackoverflow.com/questions/75406546/apply-css-styling-to-a-single-dt-datatable
Value
character
CSS
Create a modifieable datatable.
Description
Create a modifieable datatable.
Usage
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(),
columnOrder = c(),
statusColor = c(insert = "#e6e6e6", update = "#32a6d3", delete = "#e52323"),
inputUI = editbl::inputUI,
defaults = tibble(),
cloneDefaults = tibble(),
env = environment(),
canEditRow = TRUE,
canDeleteRow = TRUE,
canCloneRow = TRUE,
utilityColumns = NULL
)
Arguments
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 |
|
columnOrder |
|
statusColor |
named |
inputUI |
|
defaults |
expression that evaluates to a |
cloneDefaults |
expression that evaluates to a |
env |
|
canEditRow |
can be either of the following:
|
canDeleteRow |
can be either of the following:
|
canCloneRow |
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' ) |
Details
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.
Value
list
result
reactive
modified version ofdata
(saved)state
reactive
current state of thedata
(unsaved)selected
reactive
selected rows of thedata
(unsaved)
Author(s)
Jasper Schelfhout
Examples
## 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)
}
UI part of eDT
Description
UI part of eDT
Usage
eDTOutput(id, ...)
Arguments
id |
|
... |
arguments passed to |
Details
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.
Value
HTML
Author(s)
Jasper Schelfhout
Examples
## 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
Description
Open interactive app to explore and modify data
Usage
eDT_app(...)
Arguments
... |
arguments past to |
Details
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.
Value
data (or a modified version thereof) once you click 'close'
Server of eDT_app
Description
Server of eDT_app
Usage
eDT_app_server(moduleId = "nevergonnagiveyouup", ...)
Arguments
moduleId |
|
... |
arguments passed to eDT |
Value
moduleServer which on application stop returns version of x with made changes
Author(s)
Jasper Schelfhout
UI of eDT_app
Description
UI of eDT_app
Usage
eDT_app_ui(moduleId = "nevergonnagiveyouup", eDTId = "nevergonnaletyoudown")
Arguments
moduleId |
|
eDTId |
|
Value
HTML
Author(s)
Jasper Schelfhout
Insert rows into a tibble
Description
Insert rows into a tibble
Usage
e_rows_insert(
x,
y,
by = NULL,
...,
conflict = c("error", "ignore"),
copy = FALSE,
in_place = FALSE
)
Arguments
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 |
Details
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.
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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
Description
Insert rows into a tibble
Usage
## Default S3 method:
e_rows_insert(
x,
y,
by = NULL,
...,
conflict = c("error", "ignore"),
copy = FALSE,
in_place = FALSE
)
Arguments
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 |
Details
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.
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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_insert implementation for data.table
backends.
Description
rows_insert implementation for data.table
backends.
Usage
## S3 method for class 'dtplyr_step'
e_rows_insert(x, y, by = NULL, ..., copy = FALSE, in_place = FALSE)
Arguments
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 |
Details
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.
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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.
Author(s)
Jasper Schelfhout
rows_insert implementation for DBI backends.
Description
rows_insert implementation for DBI backends.
Usage
## S3 method for class 'tbl_dbi'
e_rows_insert(x, y, by = NULL, ..., copy = FALSE, in_place = FALSE)
Arguments
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 |
Details
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.
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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.
Author(s)
Jasper Schelfhout
Examples
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
Description
Update rows of a tibble
Usage
e_rows_update(
x,
y,
by = NULL,
...,
match,
unmatched = c("error", "ignore"),
copy = FALSE,
in_place = FALSE
)
Arguments
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 |
Details
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.
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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.
Description
rows_update implementation for data.frame backends.
Usage
## S3 method for class 'data.frame'
e_rows_update(
x,
y,
by = NULL,
match = NULL,
...,
copy = FALSE,
in_place = FALSE
)
Arguments
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 |
Details
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.
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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.
Author(s)
Jasper Schelfhout
Update rows of a tibble
Description
Update rows of a tibble
Usage
## Default S3 method:
e_rows_update(
x,
y,
by = NULL,
...,
match = match,
unmatched = c("error", "ignore"),
copy = FALSE,
in_place = FALSE
)
Arguments
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 |
Details
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.
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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.
Description
rows_update implementation for data.table backends.
Usage
## S3 method for class 'dtplyr_step'
e_rows_update(
x,
y,
by = NULL,
match = NULL,
...,
copy = FALSE,
in_place = FALSE
)
Arguments
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 |
Details
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.
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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.
Author(s)
Jasper Schelfhout
rows_update implementation for DBI backends.
Description
rows_update implementation for DBI backends.
Usage
## S3 method for class 'tbl_dbi'
e_rows_update(
x,
y,
by = NULL,
match = NULL,
...,
copy = FALSE,
in_place = FALSE
)
Arguments
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 |
Details
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.
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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.
Author(s)
Jasper Schelfhout
Examples
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)
Determine if a row can be cloned
Description
Determine if a row can be cloned
Usage
evalCanCloneRow(row, canCloneRow = TRUE, statusCol = "_editbl_status")
Arguments
row |
|
canCloneRow |
|
statusCol |
|
Details
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.
Value
boolean
Author(s)
Saar Junius
Determine if a row can be deleted
Description
Determine if a row can be deleted
Usage
evalCanDeleteRow(row, canDeleteRow = TRUE, statusCol = "_editbl_status")
Arguments
row |
|
canDeleteRow |
|
statusCol |
|
Details
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.
Value
boolean
Author(s)
Jasper Schelfhout
Determine if a row can be edited
Description
Determine if a row can be edited
Usage
evalCanEditRow(row, canEditRow = TRUE, statusCol = "_editbl_status")
Arguments
row |
|
canEditRow |
|
statusCol |
|
Details
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.
Value
boolean
Author(s)
Jasper Schelfhout
Fill data columns based on foreignTbls
Description
Fill data columns based on foreignTbls
Usage
fillDeductedColumns(tbl, foreignTbls)
Arguments
tbl |
|
foreignTbls |
list of foreign tbls as created by |
Details
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.
Value
tbl
Author(s)
Jasper Schelfhout
Replace instances of integer64 with actual NA values instead of weird default 9218868437227407266
Description
Replace instances of integer64 with actual NA values instead of weird default 9218868437227407266
Usage
fixInteger64(x)
Arguments
x |
|
Details
Value
x with integer64
columns set to bit64::as.integer64(NA)
Author(s)
Jasper Schelfhout
Create a foreign tibble
Description
Create a foreign tibble
Usage
foreignTbl(
x,
y,
by = intersect(dplyr::tbl_vars(x), dplyr::tbl_vars(y)),
naturalKey = dplyr::tbl_vars(y),
allowNew = FALSE
)
Arguments
x |
|
y |
|
by |
|
naturalKey |
|
allowNew |
|
Details
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.
Value
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
Author(s)
Jasper Schelfhout
Examples
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 types of columns in a tbl
Description
Get types of columns in a tbl
Usage
getColumnTypeSums(tbl)
Arguments
tbl |
|
Value
named list with types of the colums
Author(s)
Jasper Schelfhout
Get all columns that are not natural keys
Description
Get all columns that are not natural keys
Usage
getNonNaturalKeyCols(foreignTbls)
Arguments
foreignTbls |
list of foreign tbls as created by |
Value
character
Author(s)
Jasper Schelfhout
Get name of the tbl in the database
Description
Get name of the tbl in the database
Usage
get_db_table_name(x)
Arguments
x |
|
Value
SQL, the table name as used in the database
Add some extra columns to data to allow for / keep track of modifications
Description
Add some extra columns to data to allow for / keep track of modifications
Usage
initData(
data,
ns,
buttonCol = "buttons",
statusCol = "_editbl_status",
deleteCol = "_editbl_deleted",
iCol = "i",
canDeleteRow = TRUE,
canEditRow = TRUE,
canCloneRow = TRUE
)
Arguments
data |
|
ns |
namespace function |
buttonCol |
|
statusCol |
|
deleteCol |
|
iCol |
|
canDeleteRow |
can be either of the following:
|
canEditRow |
can be either of the following:
|
canCloneRow |
can be either of the following:
|
Value
data with extra columns buttons, status, i.
Author(s)
Jasper Schelfhout
An input server for a data.frame
Description
An input server for a data.frame
Usage
inputServer(id, data, ...)
Arguments
id |
|
data |
single row |
... |
further arguments for methods |
Details
A new method for this can be added if you wish to alter the default behavior of the pop-up modals in eDT
.
Value
modified version of data
Author(s)
Jasper Schelfhout
Examples
if(interactive()){
library(shiny)
ui <- inputUI('id')
server <- function(input,output,session){
input <- inputServer("id", mtcars[1,])
observe({print(input())})
}
shinyApp(ui, server)
}
An input server for a data.frame
Description
An input server for a data.frame
Usage
## Default S3 method:
inputServer(id, data, colnames, notEditable, foreignTbls, ...)
Arguments
id |
|
data |
single row |
colnames |
named |
notEditable |
|
foreignTbls |
list of foreignTbls. See |
... |
for compatibility with other methods |
Details
Reads all inputs ids that are identical to column names of the data and updates the data.
Value
reactive modified version of data
Author(s)
Jasper Schelfhout
An input UI for a data.frame
Description
An input UI for a data.frame
Usage
inputUI(id, ...)
Arguments
id |
|
... |
arguments passed onto methods |
Details
A new method for this can be added if you wish to alter the default behavior of the pop-up modals in eDT
.
Value
HTML. A set of input fields corresponding to the given row.
Author(s)
Jasper Schelfhout
Examples
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
Description
UI part for modal with input fields for editing
Usage
## Default S3 method:
inputUI(id, ...)
Arguments
id |
character module id |
... |
for compatibility with method |
Details
The UI elements that have an id identical to a column name are used for updating the data.
Value
HTML. A set of input fields corresponding to the given row.
Author(s)
Jasper Schelfhout
Merge a tbl with it a foreignTbl
Description
Merge a tbl with it a foreignTbl
Usage
joinForeignTbl(
tbl,
foreignTbl,
keepNA = TRUE,
by = foreignTbl$by,
copy = TRUE,
type = c("inner", "left")[1]
)
Arguments
tbl |
|
foreignTbl |
|
keepNA |
|
by |
named |
copy |
|
type |
|
Details
see also dplyr
join functions, for example dplyr::left_join
.
Value
tbl
, containing both columns from argument tbl
and argument foreignTbl
.
Author(s)
Jasper Schelfhout
Overwrite default settings with provided settings
Description
Overwrite default settings with provided settings
Usage
overwriteDefaults(defaults, settings)
Arguments
defaults |
named character vector |
settings |
named character vector |
Value
named character vector
Author(s)
Jasper Schelfhout
Start a transaction for a tibble
Description
Start a transaction for a tibble
Usage
rollbackTransaction(tbl)
Arguments
tbl |
|
Author(s)
Jasper Schelfhout
Add a row to a table in the database.
Description
Add a row to a table in the database.
Usage
rowInsert(conn, table, values)
Arguments
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. |
Value
integer number of affected rows.
Update rows in the database.
Description
Update rows in the database.
Usage
rowUpdate(conn, table, values, where)
Arguments
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. |
Value
integer number of affected rows.
rows_delete implementation for data.table backends.
Description
rows_delete implementation for data.table backends.
Usage
## S3 method for class 'dtplyr_step'
rows_delete(x, y, by = NULL, ..., unmatched, copy = FALSE, in_place = FALSE)
Arguments
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 |
Value
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()
androws_patch()
preserve the number of rows;rows_insert()
,rows_append()
, androws_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.
Author(s)
Jasper Schelfhout
Run a demo app
Description
Run a demo app
Usage
runDemoApp(app = "database", ...)
Arguments
app |
demoApp to run. Options: database / mtcars / custom |
... |
arguments passed onto the demoApp |
Details
These apps are for illustrative purposes.
Value
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
Examples
## 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 demo app
Description
Run a demo app
Usage
runDemoApp_DB()
Value
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
Run a custom demo app
Description
Run a custom demo app
Usage
runDemoApp_custom(x)
Arguments
x |
|
Value
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
Run a demo app
Description
Run a demo app
Usage
runDemoApp_mtcars()
Value
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
Run a development app
Description
Run a development app
Usage
runDevApp()
Details
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.
Value
An object that represents the app. Printing the object or passing it
to runApp()
will run the app.
Server part to use a datatable
as select input
Description
Server part to use a datatable
as select input
Usage
selectInputDT_Server(
id,
label = "",
choices,
selected = NULL,
multiple = FALSE
)
Arguments
id |
|
label |
|
choices |
|
selected |
|
multiple |
|
Value
A selection of rows from the data.frame
provided under choices.
Author(s)
Jasper Schelfhout
See Also
shiny::selectInput
. This function can be more convenient for selecting rows
with multiple columns.
Examples
## 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
Description
UI part of a DT select input
Usage
selectInputDT_UI(id)
Arguments
id |
|
Value
HTML
Author(s)
Jasper Schelfhout
Examples
## 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)
}
Get a shiny input for a column of a tbl
Description
Get a shiny input for a column of a tbl
Usage
shinyInput(x, inputId, label, selected)
Arguments
x |
column |
inputId |
shiny input Id |
label |
|
selected |
object of class of x |
Value
shiny input
Author(s)
Jasper Schelfhout
Standardize colnames argument to the format of named character vector
Description
Standardize colnames argument to the format of named character vector
Usage
standardizeArgument_colnames(colnames, data)
Arguments
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 |
|
Value
named character vector
Author(s)
Jasper Schelfhout
Standardized editable argument to be in the form of a list
Description
Standardized editable argument to be in the form of a list
Usage
standardizeArgument_editable(editable, data)
Arguments
editable |
|
data |
|
Value
list of the form list(target = foo, ...)
Author(s)
Jasper Schelfhout
Generate where sql
Description
Generate where sql
Usage
whereSQL(conn, table, column, operator = "in", values = NULL)
Arguments
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 |
Value
character sql
Author(s)
Jasper Schelfhout