dtedit | R Documentation |
dtedit - editable DataTable
dteditmod - editable DataTable, adapted for use in modules
dtedit(input, output, name, thedata, ...)
dteditmod(
input,
output,
session,
thedata,
view.cols = names(shiny::isolate(if (shiny::is.reactive(thedata)) {
thedata()
}
else {
thedata
})),
edit.cols = names(shiny::isolate(if (shiny::is.reactive(thedata)) {
thedata()
}
else {
thedata
})),
edit.label.cols = edit.cols,
delete.info.cols = view.cols,
delete.info.label.cols = delete.info.cols,
input.types,
input.choices = NULL,
input.choices.reactive = NULL,
action.buttons = NULL,
selectize = TRUE,
modal.size = "m",
text.width = "100%",
textarea.width = "570px",
textarea.height = "200px",
date.width = "100px",
datetime.width = "200px",
numeric.width = "100px",
select.width = "100%",
defaultPageLength = 10,
max.fileInputLength = 1e+08,
title.delete = "Delete",
title.edit = "Edit",
title.add = "New",
label.delete = "Delete",
label.edit = "Edit",
label.add = "New",
label.copy = "Copy",
label.save = "Save",
label.cancel = "Cancel",
icon.delete = NULL,
icon.edit = NULL,
icon.add = NULL,
icon.copy = NULL,
text.delete.modal = "Are you sure you want to delete this record?",
show.delete = TRUE,
show.update = TRUE,
show.insert = TRUE,
show.copy = TRUE,
show.search = FALSE,
callback.delete = function(data, row) {
},
callback.update = function(data, olddata, row) {
},
callback.insert = function(data, row) {
},
callback.actionButton = function(data, row, buttonID) {
},
click.time.threshold = 3,
useairDatepicker = FALSE,
datatable.options = list(pageLength = defaultPageLength),
datatable.rownames = FALSE,
datatable.call = function(...) {
DT::datatable(...)
},
...
)
input |
Shiny input object passed from the server. |
output |
Shiny output object passed from the server. |
name |
( |
thedata |
a data frame to view and edit. can be a reactive |
... |
arguments not recognized by DTedit are passed to
|
session |
Shiny session object (an environment) passed from the server. Alternatively, the 'name' (character) of the outputted editable datatable. |
view.cols |
character vector with the column names to show in the
DataTable.
This can be a subset of the full |
edit.cols |
character vector with the column names the user can
edit/add.
This can be a subset of the full |
edit.label.cols |
character vector with the labels to use on the edit
and add dialogs. The length and order of |
delete.info.cols |
character vector with the column names specifying
which values are presented on the delete dialog.
This can be a subset of the full |
delete.info.label.cols |
character vector with the labels to use on the
delete
dialog. The length and order of |
input.types |
a character vector where the name corresponds to a column
in
One case where this parameter is desirable is when a text area is required instead of a simple text input. |
input.choices |
a list of character vectors. The names of each element
in the list must
correspond to a column name in the data. The value, a character vector, are
the options
presented to the user for data entry, in the case of input type
In the case of input type In the case of input type 'fileInput“ this is the 'accept' argument, which specifies the type of file which is acceptable. Can be a case insensitive file extension (e.g. '.csv' or '.rds') or a MIME type (e.g. 'text/plain' or 'application/pdf'). |
input.choices.reactive |
a named list of reactives, referenced in
'input.choices'
to use for input type |
action.buttons |
a named list of action button columns.
Each column description is a list of
|
selectize |
Whether to use selectize.js or not. See
|
modal.size |
the size of the modal dialog. See
|
text.width |
width of text inputs. |
textarea.width |
the width of text area inputs. |
textarea.height |
the height of text area inputs. |
date.width |
the width of data inputs |
datetime.width |
the width of datetime inputs |
numeric.width |
the width of numeric inputs. |
select.width |
the width of drop down inputs. |
defaultPageLength |
number of rows to show in the data table by default. |
max.fileInputLength |
the maximum length (in bytes) of |
title.delete |
the title of the dialog box for deleting a row. |
title.edit |
the title of the dialog box for editing a row. |
title.add |
the title of the dialog box for inserting a new row. |
label.delete |
the label of the delete button. |
label.edit |
the label of the edit button. |
label.add |
the label of the add button. |
label.copy |
the label of the copy button. |
label.save |
the label of the save button. |
label.cancel |
the label of the cancel button. |
icon.delete |
the icon for the delete button, e.g.
|
icon.edit |
the icon for the edit button, e.g. |
icon.add |
the icon for the add button, e.g. |
icon.copy |
the icon for the copy button, e.g. |
text.delete.modal |
the text shown in the delete modal dialog. |
show.delete |
whether to show/enable the delete button. |
show.update |
whether to show/enable the update button. |
show.insert |
whether to show/enable the insert button. |
show.copy |
whether to show/enable the copy button. |
show.search |
whether to show/enable the add/edit search feature in add/edit modals |
callback.delete |
a function called when the user deletes a row. This function should return an updated data.frame. |
callback.update |
a function called when the user updates a row. This function should return an updated data.frame. |
callback.insert |
a function called when the user inserts a new row. This function should return an updated data.frame. |
callback.actionButton |
a function called when the user clicks an
action button.
called with arguments |
click.time.threshold |
This is to prevent duplicate entries usually by double clicking the save or update buttons. If the user clicks the save button again within this amount of time (in seconds), the subsequent click will be ignored. Set to zero to disable this feature. For developers, a message is printed using the warning function. |
useairDatepicker |
use |
datatable.options |
options passed to |
datatable.rownames |
show rownames as part of the datatable? |
datatable.call |
pre-processing call when calling
|
dtedit
is used in conjunction with uiOutput
to create editable
datatables.
dtedit
is used in a shiny application's server definition,
uiOutput
is used
in the UI (user interface) definition.
dteditmod
is used in conjunction with callModule
and
dteditmodUI
to create editable datatables in a module environment.
dteditmod
is called through callModule
in the 'server' section
of
the shiny application.
dteditmodUI
is called in the 'UI' (user-interface) section of the
shiny app.
This object will maintain data state. However, in order of the data to
persist
between Shiny instances, data needs to be saved to some external format
(e.g.
database or R data file). The callback functions provide a mechanism for this
function to interact with a permanent data storage scheme. The callback
functions are called when the user adds, updates, or deletes a row from the
data table. The callback must accept two parameters: data
and
row
.
For inserting and updating, the data
object is the current state of
data table including any additions or updates. The row
parameter
indicates
which row from data
was modified (or added). For deletions, however,
the data
represents the data table just before deleting the specified
row. That is, if callback.delete
returns a data.frame
, that
will
be the new data table; otherwise this function will remove row row
from
data
and that will become the current data table.
The callback functions may throw errors (see e.g. stop
) if there are
problems with data. That is, if data validation checks indicate data problems
before inserting or updating a row the function may throw an error. Note that
the error message will be presented to the user so providing messages
meaningful to the user is recommended. Moreover, if an error is thrown, the
modal dialog is not dismissed and the user can further edit the data and
retry the insertion or update.
Callback functions may return a data.frame
. When a data.frame
is
returned that will become the current state of the data table. If anything
else is returned then the internal data.frame
will be used.
Returns reactiveValues
theData
- the current state of DTedit
's copy of the data
view.cols
edit.cols
edit.count
- number of edits to data done within DTedit
(does not
include changes to DTedit
's copy of the data secondary to changes
of a reactive thedata
)
rows_selected
- the row number selected. initially set to NULL
fork from https://github.com/DavidPatShuiFong/DTedit
example("dtedit")
a simple example.
dtedit_demo()
demonstration of dtedit.
dtedit_reactive_demo()
reactive dataframe
dtedit_selectInputReactive_demo()
reactive selectInput
dteditmodUI
: the companion user-interface function for
dteditmod
.
example("dteditmodUI")
a simple module example with reactive
dataframe
dteditmod_demo()
a more complex module example. Database
interaction
and interactions between the data of multiple datatables.
dteditmod_fileInput_demo()
a modular example including binary
file input and action buttons.
Other Datatable Edit functions:
dteditmodUI()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.