edit-data: Shiny module to interactively edit a 'data.frame'

edit-dataR Documentation

Shiny module to interactively edit a data.frame

Description

The module generates different options to edit a data.frame: adding, deleting and modifying rows, exporting data (csv and excel), choosing editable columns, choosing mandatory columns. This module returns the edited table with the user modifications.

Usage

edit_data_ui(id)

edit_data_server(
  id,
  data_r = reactive(NULL),
  add = TRUE,
  update = TRUE,
  delete = TRUE,
  download_csv = TRUE,
  download_excel = TRUE,
  file_name_export = "data",
  var_edit = NULL,
  var_mandatory = NULL,
  return_class = c("data.frame", "data.table", "tbl_df", "raw")
)

Arguments

id

Module ID

data_r

data_r reactive function containing a data.frame to use in the module.

add

boolean, if TRUE, allows you to add a row in the table via a button at the top right

update

boolean, if TRUE, allows you to modify a row of the table via a button located in the table on the row you want to edit

delete

boolean, if TRUE, allows a row to be deleted from the table via a button in the table

download_csv

if TRUE, allows to export the table in csv format via a download button

download_excel

if TRUE, allows to export the table in excel format via a download button

file_name_export

character that allows you to choose the export name of the downloaded file

var_edit

vector of character which allows to choose the names of the editable columns

var_mandatory

vector of character which allows to choose obligatory fields to fill

return_class

Class of returned data: data.frame, data.table, tbl_df (tibble) or raw.

Value

the edited data.frame in reactable format with the user modifications

Examples

library(shiny)
library(datamods)
library(bslib)

ui <- fluidPage(
  theme = bs_theme(
    version = 5
  ),
  tags$h2(i18n("Edit data"), align = "center"),
  edit_data_ui(id = "id"),
  verbatimTextOutput("result")
)


server <- function(input, output, session) {

  edited_r <- edit_data_server(
    id = "id",
    data_r = reactive(demo_edit),
    add = TRUE,
    update = TRUE,
    delete = TRUE,
    download_csv = TRUE,
    download_excel = TRUE,
    file_name_export = "datas",
    # var_edit = c("name", "job", "credit_card_provider", "credit_card_security_code"),
    var_mandatory = c("name", "job")
  )

  output$result <- renderPrint({
    str(edited_r())
  })

}

if (interactive())
  shinyApp(ui, server)

datamods documentation built on Sept. 26, 2023, 5:07 p.m.