| Title: | An Interactive Editor for Viewing, Entering, Filtering & Editing Data |
|---|---|
| Description: | An interactive editor built on the 'Tabulator' JavaScript library to allow the interactive viewing, entering, filtering and editing of data in R, including tables stored in databases <https://dillonhammill.github.io/DataEditR/>. |
| Authors: | Dillon Hammill [aut, cre] (ORCID: <https://orcid.org/0000-0002-1407-7223>), Oli Folkerd [ctb, cph] (Author of the included Tabulator library), Lucide Contributors [cph] (Icons based on Lucide) |
| Maintainer: | Dillon Hammill <[email protected]> |
| License: | GPL-2 |
| Version: | 2.0.0 |
| Built: | 2026-11-17 00:19:49 UTC |
| Source: | https://github.com/dillonhammill/dataeditr |
data_code compares an original dataset with an edited version and
generates tidyverse-style R code (using dplyr verbs) that transforms
the original data into the edited version. The generated code uses
rename(), select(), mutate(), slice(), and
tibble::add_row() to replicate column renames, column
additions/removals, cell value changes, and row additions/removals. When
meaningful row names are present (i.e. non-default row names such as those
in mtcars), the generated code preserves them using
tibble::rownames_to_column() and tibble::column_to_rownames().
data_code(x, x_edit, name = "data")data_code(x, x_edit, name = "data")
x |
original data prior to editing, a |
x_edit |
edited data after modifications, a |
name |
character string for the name of the data object in the generated
code, set to |
a character string containing tidyverse code that can be printed to the console or written to an R script.
Dillon Hammill, [email protected]
# original data x <- data.frame( A = c(1, 2, 3), B = c("x", "y", "z"), stringsAsFactors = FALSE ) # edited data (changed a value and renamed a column) x_edit <- data.frame( A = c(1, 5, 3), Beta = c("x", "y", "z"), stringsAsFactors = FALSE ) # generate code cat(data_code(x, x_edit, name = "x"))# original data x <- data.frame( A = c(1, 2, 3), B = c("x", "y", "z"), stringsAsFactors = FALSE ) # edited data (changed a value and renamed a column) x_edit <- data.frame( A = c(1, 5, 3), Beta = c("x", "y", "z"), stringsAsFactors = FALSE ) # generate code cat(data_code(x, x_edit, name = "x"))
data_edit is a shiny application built on the MIT-licensed
'Tabulator' JavaScript library that is designed to make it easy to
interactively view, enter or edit data without any coding. data_edit
is also a wrapper for any reading or writing function to make it easy to
interactively update data saved to file, and can edit tables stored in a
database.
data_edit( x = NULL, col_bind = NULL, col_edit = TRUE, col_options = NULL, col_stretch = FALSE, col_factor = FALSE, col_names = TRUE, col_readonly = NULL, col_hide = NULL, row_bind = NULL, row_edit = TRUE, save_as = NULL, title = NULL, logo = NULL, logo_size = 30, logo_side = "left", viewer = "dialog", viewer_height = 800, viewer_width = 1200, theme = NULL, read_fun = "read.csv", read_args = NULL, write_fun = "write.csv", write_args = NULL, quiet = FALSE, hide = FALSE, code = FALSE, cancel, track = TRUE, log = NULL, autosave = TRUE, col_actions = TRUE, rules = NULL, formats = NULL, col_summary = TRUE, row_names = TRUE, col_widths = NULL, page_rows = NULL, page_cols = NULL, ... )data_edit( x = NULL, col_bind = NULL, col_edit = TRUE, col_options = NULL, col_stretch = FALSE, col_factor = FALSE, col_names = TRUE, col_readonly = NULL, col_hide = NULL, row_bind = NULL, row_edit = TRUE, save_as = NULL, title = NULL, logo = NULL, logo_size = 30, logo_side = "left", viewer = "dialog", viewer_height = 800, viewer_width = 1200, theme = NULL, read_fun = "read.csv", read_args = NULL, write_fun = "write.csv", write_args = NULL, quiet = FALSE, hide = FALSE, code = FALSE, cancel, track = TRUE, log = NULL, autosave = TRUE, col_actions = TRUE, rules = NULL, formats = NULL, col_summary = TRUE, row_names = TRUE, col_widths = NULL, page_rows = NULL, page_cols = NULL, ... )
x |
a matrix, data.frame, data.table or the name of a csv file to edit.
Tibbles are also supported. An empty table can be created by specifying
the dimensions in a vector of the form |
col_bind |
additional columns to add to the data prior to loading into editor, can be either an array containing the new data, a vector containing the new column names for empty columns or a named list containing a vector for each new column. |
col_edit |
logical indicating whether columns can be added or removed, set to TRUE by default. |
col_options |
a list named by column with the input to use for each column:
Set the limits of a slider with
|
col_stretch |
logical indicating whether columns should be stretched to fill the full width of the display, set to FALSE by default. |
col_factor |
logical indicating whether character columns should be converted to factors prior to returning the edited data, set to FALSE by default. Factor columns in the data are always returned as factors with their levels; new values become new levels after the existing ones. |
col_names |
logical indicating whether column names can be edited or a vector of column names that cannot be edited, set to TRUE by default to allow editing of column names. |
col_readonly |
names of columns that cannot be edited. Values and names of these columns are locked in the grid. |
col_hide |
names of columns to hide from the editor. Hidden columns will not be visible or editable but will be retained in the returned data. |
row_bind |
additional rows to add to the data prior to loading into editor, can be either an array containing the new data, a vector containing the new row names for empty rows or a named list containing a vector for each new column. |
row_edit |
logical indicating whether rows can be added or removed, set to TRUE by default. |
save_as |
name of a csv file to which the edited data should be saved. |
title |
optional title to show in the header, set to the name of the data by default. |
logo |
optional logo to include next to the title, supplied as the path or URL of an image. No logo is shown by default. |
logo_size |
width of the logo in pixels, set to 30 pixels by default. |
logo_side |
can be either |
viewer |
can be either |
viewer_height |
numeric to control the height of the viewer in pixels
when |
viewer_width |
numeric to control the width of the viewer in pixels when
|
theme |
a Bootstrap 5 Bootswatch theme name (e.g. |
read_fun |
name of the function to use to read in the data when |
read_args |
a named list of additional arguments to pass to
|
write_fun |
name of the function to use to write the edited version of
|
write_args |
a named list of additional arguments to pass to
|
quiet |
logical indicating whether messages should be suppressed, set to FALSE by default. |
hide |
logical indicating whether the Open and Export
menus and the Done options should be hidden. When |
code |
logical indicating whether tidyverse code required to replicate
the data edits should be printed to the console, set to |
cancel |
optional value to return when the user hits the |
track |
|
log |
name of a csv file to which the change log (who changed what
and when, see |
autosave |
logical indicating whether changes should be saved as a
draft while editing, set to |
col_actions |
logical indicating whether the column menu offers
actions that change a whole column: formulas (e.g. a new column
|
rules |
a list of rules the data should follow, each a one-sided
formula that is |
formats |
conditional formats: how to colour cells, without changing the data. A list of formats, each a one-sided formula or a list:
Names of the list are labels. When several formats colour a cell, the later one wins. Formats can also be added to a column from its menu (Conditional formatting...). |
col_summary |
logical indicating whether a summary of each column is
shown under its header: a histogram of numbers and dates or the most
common values, the share of missing values and the number of distinct
values. Click a bar to show only those rows, the missing share to show
the rows where the value is missing, or the number of values for the
details (smallest, largest, mean, ...). Set to |
row_names |
logical indicating whether the row names of the data are
shown in the editor, set to |
col_widths |
widths of the columns in pixels: one number for every
column, or numbers named by column, e.g. |
page_rows, page_cols
|
number of rows and columns to show at a time,
or |
... |
not in use. |
the edited data as a matrix or data.frame. For database tables the edited rows are returned as a data.frame after the changes have been committed.
Double-click a cell to edit it. Click and drag to select a range of cells, then copy (Ctrl+C), paste (Ctrl+V), clear (Delete) or fill down (Ctrl+D). Right click a row to insert or delete rows, and right click a column header to insert, rename, hide or delete columns. Double-click a column's name to rename it. Ctrl+Z and Ctrl+Y undo and redo changes; press ? for the full list of shortcuts.
The toolbar opens other data (Open), shows or hides column summaries and columns, filters rows (Filter, a dialog listing every filter), lists active filters, searches the data (Ctrl+F), and opens the side panel. The panel shows the selected row as a form (Record), lists every change with a button to revert it, the history of changes, broken rules and the code that reproduces the edits. Under each column name is a summary of the column: click its bars to filter the rows, or type in the boxes under it. The status bar shows how many rows and columns are on screen and summarises the selected cells. The menu next to Done chooses whether all data or only what is on screen is returned.
Data read from SPSS, Stata or SAS files with haven keeps its variable
labels (shown when hovering over a column name), value labels and SPSS
user-defined missing values. Cells show each value with its label
(1 Male), the cell editor offers the labels, and a label typed or
pasted into a cell is stored as its value. Labels... in the column
menu changes the variable label and value labels, and Change type
turns labelled values into factors or text with their labels. The
returned data and the generated code keep the labels.
Supply a dbplyr lazy table (e.g. dplyr::tbl(con, "artists"))
or a db_table() to edit a database table. Rows are matched by
primary key, changes are staged until you press Done, and you are
asked to confirm before anything is written. Writes happen in a single
transaction and are rolled back if any row was changed by someone else in
the meantime. Adding, removing and renaming columns is disabled for
database tables.
Every change is recorded with the time and the user name. The
History tab of the review panel lists the changes step by step and
each step can be given a note, for example to say why a value was
corrected. Supply log to keep this record in a file.
With autosave = TRUE the changes are saved as a draft a moment after
each edit. Drafts are kept in tools::R_user_dir("DataEditR",
"data"); set options(DataEditR.drafts = ) to use another folder.
A draft is removed when Done or Cancel is pressed, when it
is restored or discarded, and after 30 days. Pressing Cancel asks
for confirmation before changes are discarded.
Rules are checked after every change. Missing values pass a rule unless
the rule says otherwise, so ~ end >= start only checks rows where
both are filled in; add "Start is required" = ~ !is.na(start) to
require a value. In the editor, a column's menu (Rules...) makes it
required or unique, sets limits or a pattern, or adds a formula.
A column's menu (or right-clicking its header) has actions that change the
whole column: Formula... (a new column or new values from an R
expression, e.g. round(mpg * 0.425, 1)), Find and
replace..., Recode values..., Change type and sorting. Each
shows a preview and is recorded as one dplyr verb, so the generated
code reads mutate(kpl = round(mpg * 0.425, 1), .after = mpg)
rather than listing every value. Formulas can use column names and common
functions (arithmetic, round(), ifelse(), paste(),
case_when(), as.Date(), ...), but not other code.
data_edit() is also available from the RStudio Addins menu
as Interactive Data Editor. Highlight the name of a data frame,
matrix or database table in the source editor or console and run the add-in
to open it in the editor; with nothing highlighted an empty table is opened.
The add-in can be bound to a keyboard shortcut through Tools > Modify
Keyboard Shortcuts.
Dillon Hammill, [email protected]
if(interactive()) { data_edit(mtcars) }if(interactive()) { data_edit(mtcars) }
dataEdit renders an editable, spreadsheet-like grid built on the
MIT-licensed 'Tabulator' JavaScript library. Edits are sent to R as
cell-level changes rather than whole tables, which keeps large datasets
responsive and makes undo/redo, change tracking and database commits
possible.
dataEditUI( id, height = "65vh", toolbar = TRUE, toolbar_left = NULL, toolbar_right = NULL ) dataEditServer( id, data = reactive(NULL), col_bind = NULL, col_edit = TRUE, col_options = NULL, col_stretch = FALSE, col_names = TRUE, col_readonly = NULL, col_hide = NULL, col_factor = FALSE, row_bind = NULL, row_edit = TRUE, row_index = reactive(NULL), rows = NULL, columns = NULL, quiet = FALSE, read_fun = "read.csv", read_args = NULL, track = TRUE, code_name = "data", autosave = FALSE, user = NULL, col_actions = TRUE, rules = NULL, formats = NULL, col_summary = TRUE, history = NULL, row_names = TRUE, col_widths = NULL, page_rows = NULL, page_cols = NULL, ... )dataEditUI( id, height = "65vh", toolbar = TRUE, toolbar_left = NULL, toolbar_right = NULL ) dataEditServer( id, data = reactive(NULL), col_bind = NULL, col_edit = TRUE, col_options = NULL, col_stretch = FALSE, col_names = TRUE, col_readonly = NULL, col_hide = NULL, col_factor = FALSE, row_bind = NULL, row_edit = TRUE, row_index = reactive(NULL), rows = NULL, columns = NULL, quiet = FALSE, read_fun = "read.csv", read_args = NULL, track = TRUE, code_name = "data", autosave = FALSE, user = NULL, col_actions = TRUE, rules = NULL, formats = NULL, col_summary = TRUE, history = NULL, row_names = TRUE, col_widths = NULL, page_rows = NULL, page_cols = NULL, ... )
id |
unique identifier for the module to prevent namespace clashes when making multiple calls to this shiny module. |
height |
height of the grid as a valid CSS unit, set to |
toolbar |
logical indicating whether the toolbar (undo/redo, columns,
find, review changes, code), review panel and status bar should be shown
around the grid, set to |
toolbar_left, toolbar_right
|
optional UI elements to add at the start
or end of the toolbar ( |
data |
a reactive expression containing an array (e.g. data.frame,
matrix or data.table), a database table (see |
col_bind |
additional columns to add to the data prior to loading into editor, can be either an array containing the new data, a vector containing the new column names for empty columns or a named list containing a vector for each new column. |
col_edit |
logical indicating whether columns can be added or removed, set to TRUE by default. |
col_options |
a list named by column with the input to use for each column:
Set the limits of a slider with
|
col_stretch |
logical indicating whether columns should be stretched to fill the full width of the display, set to FALSE by default. |
col_names |
logical indicating whether column names can be edited or a vector of column names that cannot be edited, set to TRUE by default to allow editing of column names. |
col_readonly |
names of columns that cannot be edited. Values and names of these columns are locked in the grid. |
col_hide |
names of columns to hide from the editor. Hidden columns will not be visible or editable but will be retained in the data returned by the module. |
col_factor |
logical indicating whether character columns should be converted to factors prior to returning the edited data, set to FALSE by default. Factor columns in the data are always returned as factors with their levels; new values become new levels after the existing ones. |
row_bind |
additional rows to add to the data prior to loading into editor, can be either an array containing the new data, a vector containing the new row names for empty rows or a named list containing a vector for each new column. |
row_edit |
logical indicating whether rows can be added or removed, set to TRUE by default. |
row_index |
retained for backwards compatibility and no longer required. Rows now carry stable identifiers, so new rows are numbered automatically. |
rows |
a reactive expression returning the row indices (positions in
the data returned by this module) to display, or |
columns |
a reactive expression returning the names of the columns to
display, or |
quiet |
logical to suppress messages and notifications. |
read_fun |
name of the function to use to read in the data when a file
is selected, set to |
read_args |
a named list of additional arguments to pass to
|
track |
|
code_name |
name of the data used in the code shown in the review
panel, set to |
autosave |
logical indicating whether changes should be saved as a
draft while editing, so that they can be restored if the app is closed
before they are saved. When the same data is opened again by the same
user, they are asked whether to restore the changes. Set to |
user |
name of the person editing, recorded in the change log (see
|
col_actions |
logical indicating whether the column menu offers
actions that change a whole column: formulas, find and replace,
recoding values, changing the type and sorting the rows. They are shown
in the generated code as one |
rules |
a list of rules the data should follow, each a one-sided
formula that is |
formats |
conditional formats: how to colour cells, without changing the data. A list of formats, each a one-sided formula or a list:
Names of the list are labels. When several formats colour a cell, the later one wins. Users can add formats to a column from its menu (Conditional formatting...). |
col_summary |
logical indicating whether a summary of each column
(a histogram or the most common values, the share of missing values and
the number of distinct values) is shown under its header, set to
|
history |
the change log of earlier editing sessions to list in the
History tab under the changes of this session: a data frame with
the columns of |
row_names |
logical indicating whether the row names of the data are
shown in the editor, set to |
col_widths |
widths of the columns in pixels: one number for every
column, or numbers named by column, e.g. |
page_rows, page_cols
|
number of rows and columns to show at a time,
or |
... |
not in use. |
reactive expression containing the edited data. Pass it to
dataEditCommit() to save the changes (e.g. write them to a
database) and to dataEditChanges() for a summary of the
changes that have not been saved yet. The reactive also carries the
attribute "view", a reactive returning only the rows and columns on
display.
Dillon Hammill, [email protected]
if (interactive()) { library(shiny) ui <- fluidPage( dataInputUI("input-1"), dataOutputUI("output-1"), dataEditUI("edit-1") ) server <- function(input, output, session) { data_to_edit <- dataInputServer("input-1") data_edit <- dataEditServer("edit-1", data = data_to_edit ) dataOutputServer("output-1", data = data_edit ) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( dataInputUI("input-1"), dataOutputUI("output-1"), dataEditUI("edit-1") ) server <- function(input, output, session) { data_to_edit <- dataInputServer("input-1") data_edit <- dataEditServer("edit-1", data = data_to_edit ) dataOutputServer("output-1", data = data_edit ) } shinyApp(ui, server) }
dataEditCommit() saves the changes made in a data editor created by
dataEditServer(), for example when the user presses a
Save button in your shiny application. dataEditChanges()
returns a summary of the changes that have not been saved yet, which is
useful to enable a Save button or to ask the user to confirm.
dataEditLog() returns the change log: every change made in the
editor, with when it was made and by whom.
dataEditCommit(x) dataEditChanges(x) dataEditLog(x) dataEditProblems(x)dataEditCommit(x) dataEditChanges(x) dataEditLog(x) dataEditProblems(x)
x |
the reactive expression returned by |
For database tables (see db_table()) the staged changes are
written to the database in a single transaction: edited rows are updated,
removed rows are deleted and new rows are inserted. If any row has been
changed or removed by someone else since it was loaded, the whole commit is
rolled back, nothing is written and an error of class
"editr_conflict" is raised; the changes stay in the editor so the
user can try again. After a successful commit the rows are loaded from the
database again, so new rows show the keys generated by the database and
the editor starts afresh.
For data in your R session (data frames, matrices, files, ...) nothing is
written; the current data simply becomes the new starting point, so the
review panel, change highlights and generated code start again from the
committed data. Write the data returned by dataEditServer() wherever
it needs to go in the same observer.
dataEditCommit() invisibly returns a list with the number of
rows updated, inserted and deleted, the number of
columns added, removed or renamed and the log entries of
the changes that were saved (NULL if no data is loaded).
dataEditChanges() returns the same counts plus the number of
edited cells and the total number of changes.
dataEditLog() returns the change log. Both must be called in a
reactive context (they update as the data is edited).
Every change made in the editor is recorded, one row per changed cell (or per row or column that was added, removed or renamed), in a data frame with the columns:
when the editing session started (e.g.
"2026-11-02 09:27:27.123"), which names the session when logs of
many sessions are kept together. Restoring a draft carries on its
session.
when the change was made.
who made it (see the user argument of
dataEditServer()).
number of the action the change belongs to. One action (typing a value, a paste, a fill, an undo, ...) is one step, the same unit that undo works with.
how the change was made: "edit", "paste",
"fill", "shift" (cells inserted or deleted, moving the
cells below), "clear", "undo", "redo" or
"revert" (from the review panel), or the column action:
"formula", "replace", "recode", "type" or
"sort".
for column actions, the dplyr code of the action, e.g.
mutate(kpl = mpg * 0.425).
"edit", "add row", "remove row",
"add column", "remove column", "rename column",
"change type" or "reorder rows".
the row name, the key of a database row or else the row number in the data that was opened (new rows are numbered after the last row).
the name of the column.
the values before and after, as text. For a removed row
old lists the values of the whole row.
the note added to the step in the History tab, which users can use to say why a change was made.
Undoing a change is recorded as a new step, so the log is a complete
record of what happened. The log is kept for the whole session, including
across commits; the entries saved by a commit are returned by
dataEditCommit() so that they can be written next to the data (for
example to a log table in the same database).
Dillon Hammill, [email protected]
if (interactive() && requireNamespace("RSQLite", quietly = TRUE)) { library(shiny) con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") DBI::dbExecute(con, "CREATE TABLE cars (id INTEGER PRIMARY KEY, model TEXT, mpg REAL)") DBI::dbAppendTable(con, "cars", data.frame( model = rownames(mtcars), mpg = mtcars$mpg)) ui <- bslib::page_fluid( shinyjs::useShinyjs(), dataEditUI( "cars", toolbar_right = actionButton("save", "Save", class = "btn-primary") ) ) server <- function(input, output, session) { cars <- dataEditServer("cars", data = dplyr::tbl(con, "cars")) # only enable saving when there is something to save observe({ ch <- dataEditChanges(cars) shinyjs::toggleState("save", !is.null(ch) && ch$total > 0) }) observeEvent(input$save, { res <- tryCatch(dataEditCommit(cars), editr_conflict = function(e) e) if (inherits(res, "editr_conflict")) { showNotification(conditionMessage(res), type = "error") } else { # keep a record of who changed what next to the data if (nrow(res$log) > 0) { DBI::dbWriteTable(con, "cars_log", res$log, append = TRUE) } showNotification(paste(res$updated, "updated,", res$inserted, "added and", res$deleted, "removed")) } }) } shinyApp(ui, server) }if (interactive() && requireNamespace("RSQLite", quietly = TRUE)) { library(shiny) con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") DBI::dbExecute(con, "CREATE TABLE cars (id INTEGER PRIMARY KEY, model TEXT, mpg REAL)") DBI::dbAppendTable(con, "cars", data.frame( model = rownames(mtcars), mpg = mtcars$mpg)) ui <- bslib::page_fluid( shinyjs::useShinyjs(), dataEditUI( "cars", toolbar_right = actionButton("save", "Save", class = "btn-primary") ) ) server <- function(input, output, session) { cars <- dataEditServer("cars", data = dplyr::tbl(con, "cars")) # only enable saving when there is something to save observe({ ch <- dataEditChanges(cars) shinyjs::toggleState("save", !is.null(ch) && ch$total > 0) }) observeEvent(input$save, { res <- tryCatch(dataEditCommit(cars), editr_conflict = function(e) e) if (inherits(res, "editr_conflict")) { showNotification(conditionMessage(res), type = "error") } else { # keep a record of who changed what next to the data if (nrow(res$log) > 0) { DBI::dbWriteTable(con, "cars_log", res$log, append = TRUE) } showNotification(paste(res$updated, "updated,", res$inserted, "added and", res$deleted, "removed")) } }) } shinyApp(ui, server) }
Shiny module for filtering data
dataFilterUI(id) dataFilterServer( id, data = reactive(NULL), hide = FALSE, hover_text = NULL, reset = NULL )dataFilterUI(id) dataFilterServer( id, data = reactive(NULL), hide = FALSE, hover_text = NULL, reset = NULL )
id |
unique identifier for the module to prevent namespace clashes when making multiple calls to this shiny module. |
data |
an array wrapped in |
hide |
logical indicating whether the data filtering user interface should be hidden from the user, set to FALSE by default. |
hover_text |
text to display on download button when user hovers cursor over button, set to NULL by default to turn off hover text. |
reset |
optional reactive expression that resets the filters whenever
it changes. By default filters are reset whenever |
a list of reactive objects containing the filtered data and
indices for filtered rows.
Dillon Hammill, [email protected]
if (interactive()) { library(shiny) library(shinyjs) ui <- fluidPage( useShinyjs(), dataInputUI("input1"), dataFilterUI("filter1"), tableOutput("data1") ) server <- function(input, output, session) { data_input <- dataInputServer("input1") # list with slots data and rows (indices) data_filter <- dataFilterServer("filter1", data = data_input ) output$data1 <- renderTable({ data_filter$data() }) } shinyApp(ui, server) }if (interactive()) { library(shiny) library(shinyjs) ui <- fluidPage( useShinyjs(), dataInputUI("input1"), dataFilterUI("filter1"), tableOutput("data1") ) server <- function(input, output, session) { data_input <- dataInputServer("input1") # list with slots data and rows (indices) data_filter <- dataFilterServer("filter1", data = data_input ) output$data1 <- renderTable({ data_filter$data() }) } shinyApp(ui, server) }
Shiny module for data input
dataInputUI(id, cellWidths = c("50%", "48%")) dataInputServer( id, data = NULL, read_fun = "read.csv", read_args = NULL, hide = FALSE, envir = parent.frame() )dataInputUI(id, cellWidths = c("50%", "48%")) dataInputServer( id, data = NULL, read_fun = "read.csv", read_args = NULL, hide = FALSE, envir = parent.frame() )
id |
unique identifier for the module to prevent namespace clashes when making multiple calls to this shiny module. |
cellWidths |
a vector of length 2 to control the relative widths of the
|
data |
can be either the name of a dataset or file as a character string (e.g. "mtcars" or "mtcars.csv") or a vector column names (e.g. c("A", "B", "C")) or template dimensions (e.g. c(10,10)). |
read_fun |
name of the function to use to read in the data when a file
is selected, set to |
read_args |
a named list of additional arguments to pass to
|
hide |
logical indicating whether the data input user interface should be hidden from the user, set to FALSE by default. |
envir |
the environment in which to search for the supplied data, set to
the |
Dillon Hammill, [email protected]
if (interactive()) { library(shiny) ui <- fluidPage( dataInputUI("input1"), tableOutput("data1") ) server <- function(input, output, session) { data_input1 <- dataInputServer("input1") output$data1 <- renderTable({ data_input1() }) } shinyApp(ui, server) }if (interactive()) { library(shiny) ui <- fluidPage( dataInputUI("input1"), tableOutput("data1") ) server <- function(input, output, session) { data_input1 <- dataInputServer("input1") output$data1 <- renderTable({ data_input1() }) } shinyApp(ui, server) }
Shiny module for data output
dataOutputUI(id, icon = "download") dataOutputServer( id, data = reactive(NULL), save_as = NULL, write_fun = "write.csv", write_args = NULL, hide = FALSE, hover_text = NULL )dataOutputUI(id, icon = "download") dataOutputServer( id, data = reactive(NULL), save_as = NULL, write_fun = "write.csv", write_args = NULL, hide = FALSE, hover_text = NULL )
id |
unique identifier for the module to prevent namespace clashes when making multiple calls to this shiny module. |
icon |
supplied to |
data |
an object of class data.frame wrapped in |
save_as |
name of the file to which the data should be saved, overrides input file path if supplied. |
write_fun |
name of the function to use when writing the data to file,
set to |
write_args |
a named list of additional arguments to pass to
|
hide |
logical indicating whether the data input user interface should be hidden from the user, set to FALSE by default. |
hover_text |
text to display on download button when user hovers cursor over button, set to NULL by default to turn off hover text. |
dataOutputServer returns the data to be saved, wrapped in
reactive.
Dillon Hammill, [email protected]
if (interactive()) { library(shiny) library(shinyjs) ui <- fluidPage( useShinyjs(), dataInputUI("input1"), dataOutputUI("output1"), tableOutput("data1") ) server <- function(input, output, session) { data_input1 <- dataInputServer("input1") output$data1 <- renderTable({ data_input1() }) dataOutputServer("output1", data = data_input1 ) } shinyApp(ui, server) }if (interactive()) { library(shiny) library(shinyjs) ui <- fluidPage( useShinyjs(), dataInputUI("input1"), dataOutputUI("output1"), tableOutput("data1") ) server <- function(input, output, session) { data_input1 <- dataInputServer("input1") output$data1 <- renderTable({ data_input1() }) dataOutputServer("output1", data = data_input1 ) } shinyApp(ui, server) }
Shiny module for selecting data
dataSelectUI(id) dataSelectServer( id, data = reactive(NULL), hide = FALSE, hover_text = NULL, reset = NULL )dataSelectUI(id) dataSelectServer( id, data = reactive(NULL), hide = FALSE, hover_text = NULL, reset = NULL )
id |
unique identifier for the module to prevent namespace clashes when making multiple calls to this shiny module. |
data |
an array wrapped in |
hide |
logical indicating whether the data selection user interface should be hidden from the user, set to FALSE by default. |
hover_text |
text to display on download button when user hovers cursor over button, set to NULL by default to turn off hover text. |
reset |
optional reactive expression that resets the selection whenever
it changes. By default the selection is reset whenever |
a list of reactive objects containing the filtered data,
indices for selected columns and the names of the selected
columns.
Dillon Hammill, [email protected]
if (interactive()) { library(shiny) library(shinyjs) ui <- fluidPage( useShinyjs(), dataInputUI("input1"), dataSelectUI("select1"), tableOutput("data1") ) server <- function(input, output, session) { data_input <- dataInputServer("input1") data_select <- dataSelectServer("select1", data = data_input ) output$data1 <- renderTable({ data_select$data() }) } shinyApp(ui, server) }if (interactive()) { library(shiny) library(shinyjs) ui <- fluidPage( useShinyjs(), dataInputUI("input1"), dataSelectUI("select1"), tableOutput("data1") ) server <- function(input, output, session) { data_input <- dataInputServer("input1") data_select <- dataSelectServer("select1", data = data_input ) output$data1 <- renderTable({ data_select$data() }) } shinyApp(ui, server) }
The purpose of this module is to merge changes made to a subset of the data with the master copy of the data.
dataSyncUI(id) dataSyncServer( id, data = reactive(NULL), data_subset = reactive(NULL), rows = reactive(NULL), columns = reactive(NULL), hide = FALSE, hover_text = NULL, auto = FALSE )dataSyncUI(id) dataSyncServer( id, data = reactive(NULL), data_subset = reactive(NULL), rows = reactive(NULL), columns = reactive(NULL), hide = FALSE, hover_text = NULL, auto = FALSE )
id |
unique identifier for the module to prevent namespace clashes when making multiple calls to this shiny module. |
data |
master copy of the data. |
data_subset |
subset of |
rows |
the row indices of |
columns |
the column indices of |
hide |
logical indicating whether the data synchronisation user interface should be hidden from the user, set to FALSE by default. |
hover_text |
text to display on download button when user hovers cursor over button, set to NULL by default to turn off hover text. |
auto |
logical indicating whether data synchronisation should happen
automatically whenever |
Dillon Hammill, [email protected]
if(interactive()){ library(shiny) library(shinyjs) ui <- fluidPage( useShinyjs(), dataInputUI("input1"), dataFilterUI("filter1"), dataEditUI("edit1") ) server <- function(input, output, session) { values <- reactiveValues( data = NULL, data_subset = NULL ) data_input <- dataInputServer("input1") data_edit <- dataEditServer( "edit1", data = data_input ) data_sync <- dataSyncServer( "sync1", data = data_input, data_subset = data_edit, rows = NULL, columns = NULL, auto = TRUE ) } shinyApp(ui, server) }if(interactive()){ library(shiny) library(shinyjs) ui <- fluidPage( useShinyjs(), dataInputUI("input1"), dataFilterUI("filter1"), dataEditUI("edit1") ) server <- function(input, output, session) { values <- reactiveValues( data = NULL, data_subset = NULL ) data_input <- dataInputServer("input1") data_edit <- dataEditServer( "edit1", data = data_input ) data_sync <- dataSyncServer( "sync1", data = data_input, data_subset = data_edit, rows = NULL, columns = NULL, auto = TRUE ) } shinyApp(ui, server) }
db_table() describes a database table for data_edit(). You can
usually skip it and pass a dbplyr lazy table directly, e.g.
data_edit(tbl(con, "artists")); use db_table() when the key
cannot be detected automatically or the query is not a simple table
reference.
db_table( x, table = NULL, key = NULL, limit = NULL, check = TRUE, readonly = NULL )db_table( x, table = NULL, key = NULL, limit = NULL, check = TRUE, readonly = NULL )
x |
a |
table |
name of the table to write to, a character string or a
|
key |
name(s) of the column(s) that uniquely identify each row. When
|
limit |
maximum number of rows to load into the editor at a time, set
to |
check |
logical indicating whether updates and deletes should verify
that rows have not changed in the database since they were loaded
(optimistic concurrency), set to |
readonly |
|
Rows are matched to the database through the key columns. Edits are staged in the editor and only written when you press Done and confirm the commit. All changes are written in a single transaction: if any row has been changed by someone else since it was loaded (or no longer exists), the whole commit is rolled back and nothing is written. Adding, removing and renaming columns is disabled for database tables.
Tables do not have to fit in memory: at most limit rows are loaded
at a time, and Rows in the toolbar loads other rows (those matching
a filter, in a chosen order), with the filter and sorting done by the
database. Queries that cannot be written back (SQL, joins, or tables
without a primary key, e.g. read_parquet() with DuckDB) are opened
read-only, so large files can still be explored.
an object of class editr_db_table to pass to
data_edit() or dataEditServer().
Dillon Hammill, [email protected]
if (interactive() && requireNamespace("RSQLite", quietly = TRUE)) { con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") DBI::dbExecute(con, "CREATE TABLE cars (id INTEGER PRIMARY KEY, model TEXT, mpg REAL)") DBI::dbAppendTable(con, "cars", data.frame( model = rownames(mtcars), mpg = mtcars$mpg)) # key detected automatically data_edit(dplyr::tbl(con, "cars")) # explicit table description data_edit(db_table(con, table = "cars", key = "id")) }if (interactive() && requireNamespace("RSQLite", quietly = TRUE)) { con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:") DBI::dbExecute(con, "CREATE TABLE cars (id INTEGER PRIMARY KEY, model TEXT, mpg REAL)") DBI::dbAppendTable(con, "cars", data.frame( model = rownames(mtcars), mpg = mtcars$mpg)) # key detected automatically data_edit(dplyr::tbl(con, "cars")) # explicit table description data_edit(db_table(con, table = "cars", key = "id")) }