Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jbryer/DTedit
Editable DataTables for shiny apps
https://github.com/jbryer/DTedit
Last synced: 27 days ago
JSON representation
Editable DataTables for shiny apps
- Host: GitHub
- URL: https://github.com/jbryer/DTedit
- Owner: jbryer
- License: other
- Created: 2017-01-14T15:48:48.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-09T18:23:29.000Z (5 months ago)
- Last Synced: 2024-11-09T06:18:19.900Z (about 1 month ago)
- Language: R
- Homepage:
- Size: 4.97 MB
- Stars: 129
- Watchers: 6
- Forks: 65
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-shiny-extensions - DTedit - Editable DataTables for Shiny apps. (UI Components / Table)
- jimsghstars - jbryer/DTedit - Editable DataTables for shiny apps (R)
README
## Editable DataTables for shiny apps.
**Author:** Jason Bryer, Ph.D.
**Email:** [email protected]Use the `devtools` package to install the development version of `DTedit`:
```r
devtools::install_github('jbryer/DTedit')
```The `dtedit_demo` will run a sample `shiny` app with to editable data tables.
```r
DTedit::dtedit_demo()
```![DTedit Screen Shot](inst/screens/dtedit_books_edit.png)
#### Getting Started with `DTedit`
You can download a simple shiny app using `DTedit` here: [inst/template/app.R](inst/template/app.R)
There are three steps to using `DTedit` in your shiny application.
1. Define callback function for inserting, updating, and deleting data.
```r
my.insert.callback <- function(data, row) {
mydata <- rbind(data, mydata)
return(mydata)
}my.update.callback <- function(data, olddata, row) {
mydata[row,] <- data[1,]
return(mydata)
}my.delete.callback <- function(data, row) {
mydata[row,] <- NULL
return(mydata)
}
```Typically these functions would interact with a database. As written here, the data would be lost between shiny sessions.
2. Create the `dtedit_server` object within your `server` function.
```r
DTedit::dtedit_server(
id = 'mycontacts',
thedata = mydata,
edit.cols = c('name', 'email', 'useR', 'notes'),
edit.label.cols = c('Name', 'Email Address', 'Are they an R user?', 'Additional notes'),
input.types = c(notes='textAreaInput'),
view.cols = c('name', 'email', 'useR'),
callback.update = my.update.callback,
callback.insert = my.insert.callback,
callback.delete = my.delete.callback)
```The `id` parameter defines the name of the object available to the `uiOutput`. The `thedata` is a `data.frame` for the initial view of the data table. This can be an empty (i.e. no rows) `data.frame`. The structure of the `data.frame` will define the inputs (e.g. `factor`s will be drop down, `Date` will use `dateInput`, `numeric`s will use `numericInput`, etc.). There are many other parameters to custom the behavior of `dtedit`, see `?dtedit` for the full list.
3. Use `dtedit_ui` in your UI to display the editable data table.
The `id` you will pass to `dteditui` is the name you passed to the `dtedit_server` created on the server side.
```r
dtedit_ui('mycontacts')
```