eDT {editbl} | R Documentation |
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(),
statusColor = c(insert = "#e6e6e6", update = "#32a6d3", delete = "#e52323"),
inputUI = editbl::inputUI,
defaults = tibble(),
env = environment()
)
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 |
|
statusColor |
named |
inputUI |
|
defaults |
expression that evaluates to a |
env |
|
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)})
}