| 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], Saar Junius [aut] |
| Maintainer: | Jasper Schelfhout <[email protected]> |
| License: | GPL-3 |
| Version: | 1.3.2 |
| Built: | 2026-05-25 12:11:36 UTC |
| Source: | https://github.com/openanalytics/editbl |
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)
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) }
Delete rows from a tibble
e_rows_delete( x, y, by = NULL, ..., unmatched = c("error", "ignore"), copy = FALSE, in_place = FALSE )e_rows_delete( x, y, by = NULL, ..., 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. |
unmatched |
For One of:
|
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_delete.
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.
Delete rows from a tibble
## Default S3 method: e_rows_delete( x, y, by = NULL, ..., unmatched = c("error", "ignore"), copy = FALSE, in_place = FALSE )## Default S3 method: e_rows_delete( x, y, by = NULL, ..., 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. |
unmatched |
For One of:
|
copy |
If |
in_place |
Should When |
Mainly a wrapper around rows_delete.
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
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(), 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 )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 )
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' ) |
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)
edited reactive edited rows (saved)
inserted reactive inserted rows (saved)
deleted reactive deleted rows (saved)
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) }
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) }
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
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
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
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)) }
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) }