I am working with the DTedit package and would like to implement two functionalities. I am attaching the code sample from the package author's github. The two things that I would like to implement are:
a button that saves the data after any new additions or modifications to the table to a local file. Ideally we can append all new additions (or editions) to an existing csv file. The app will be in rstudio server so we can add this file to the www folder.
The second functionality is that the app must pull the data from the csv and show it when the user opens the app, instead of showing an empty table like the one on the code before.
I've been trying a few options and look at a few tutorials on the internet but haven't been able to solve these two questions.
library(shiny)
library(DTedit)
##### Create the Shiny server
server <- function(input, output) {
mydata <- data.frame(name = character(),
email = character(),
useR = factor(levels = c('Yes', 'No')),
notes = character(),
stringsAsFactors = FALSE)
##### Callback functions.
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 <- mydata[-row,]
return(mydata)
}
##### Create the DTedit object
DTedit::dtedit(input, output,
name = '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)
}
##### Create the shiny UI
ui <- fluidPage(
h3('DTedit Template'),
uiOutput('mycontacts')
)
##### Start the shiny app
shinyApp(ui = ui, server = server)