Shiny Contest Submission: Table Editor Shiny App

This is a Datatable editor. User can add, modify and delete the data they want from ui side. Click "Save" will store the change.

Shiny Link: https://appforiarteam.shinyapps.io/DT_Editor_Example2/
RStudio Cloud: https://rstudio.cloud/project/213331
Github Repo: https://github.com/jienagu/DT-Editor

Welcome to let me know any suggestions!

13 Likes

Wow, that’s a great app! I didn’t know this was doable so that could solve many things for me.
Do you know how the app behaves when 2 users update the table at the same time?

Cheers
C

1 Like

Thanks @stirlingFR! I am glad that it is useful for you. I haven't tried if 2 or more users update the table simultaneously. I think the table will depends on who click "save" button first since all of modification will not be permanently updated until user click "save". This is a very good question! Thanks again!

Extra version of editable DT shiny app

Inspired by Jonathan Regenstein (@jkr216 ), it is a great idea to use editable DT tables as shiny inputs and passed as reactives (double click to edit; similar to rhandsontable). So I wrote another version of the DT editor that user can double click to edit cell(s) they want. In case they accidentally edit cells, click "reset" to go back. When it is ready, click "save" to permanently save the edited table. Hopefully it is useful.

Repo: GitHub - jienagu/DT_editable_as_shiny_input: Editable DT tables as shiny inputs and passed as reactives
RStudio Cloud: Posit Cloud

92966756

3 Likes

Hello. It seems like a very useful app. Do you have any ideas on what would be the best way to save the table to a master file, for example in dropbox. So when different users save data we can always have the latest version of the save available in a database?

2 Likes

Its Inbuilt Functionality of DT Datatable
Refer this for Basic Changes: https://rstudio.github.io/DT/

We can also add Funcitionality to tables like embedding colors, styling text, shading the percents and many more, kindly check this for the same : https://rstudio.github.io/DT/functions.html

To add checklist to table you can do that, check this out for same : https://rstudio.github.io/DT/011-radio.html

1 Like

Great idea! Yes, it can feasible. If you are interested in this feature, check rdrop2 Package (https://github.com/karthik/rdrop2#accessing-dropbox-on-shiny-and-remote-servers). Then go to my server.r and simply add drop_upload("note.rds") under saveRDS(vals_trich$Data, "note.rds") (around line 82-87) to upload the table to a master file. Refer to rdrop2 doc, if you accessing Dropbox on Shiny and remote servers, you can also save the output of drop_auth into an R object, sink that to disk, and pass that as a token. I personally use this app as my work notebook for projects. :slight_smile:

Thanks @GauravChavan. I like the idea of adding functionalities (such as styling text) to DT tables. :+1:

1 Like

Great! Thanks for the feedback. Will try this approach.

1 Like

Sounds good! thanks Jiena.

Can you please provide the code as well

also I tried with another way here is the code

library(shiny)
library(DTedit)
mydata1 <- read.csv('Item_master.csv', row.names = NULL)
##### Create the Shiny server
server <- function(input, output) {
  mydata <- data.frame(Sr =numeric(),
                       Category=character(),
                       Item=character(),
                       Weight=numeric(),
                       SKUNo=character() ,
                       SellingPrice =numeric(),
                       Costprice =numeric(),
                       Overheads =numeric(),
                       stringsAsFactors = FALSE)
  
  
  
  mydata <- as.data.frame(mydata1)
  ##### Callback functions.
  my.insert.callback <- function(data, row) {
    write.csv(data, file = "item_master.csv", row.names = FALSE, col.names = TRUE)
    mydata <-data
      #rbind(data, mydata)
    
    return(mydata)
  }
  
  my.update.callback <- function(data, olddata, row) {
    mydata[row,] <- data[1,]
    mydata<-data
    write.csv(mydata, file = "item_master.csv")
    return(mydata)
  }
  
  my.delete.callback <- function(data, row) {
    mydata <- data[-row,]
    write.csv(mydata, file = "item_master.csv", row.names = FALSE, col.names = TRUE)
    return(mydata)
  }
  
  ##### Create the DTedit object
  DTedit::dtedit(input, output,
                 name = 'mycontacts',
                 thedata = mydata,
                 edit.cols = c('Sr', 'Category','Item','Weight','SKUNo' ,'SellingPrice','Costprice','Overheads'),
                 edit.label.cols = c('Sr', 'Category','Item','Weight','SKUNo' ,'SellingPrice','Costprice','Overheads'),
                 #input.types = c(notes='textAreaInput'),
                 view.cols = c('Sr', 'Category','Item','Weight','SKUNo' ,'SellingPrice','Costprice','Overheads'),
                 callback.update = my.update.callback,
                 callback.insert = my.insert.callback,
                 callback.delete = my.delete.callback
                 #mydata1 <- as.data.frame(mydata),
  )
  
}

##### Create the shiny UI
ui <- fluidPage(
  #actionButton("addButton", "UPLOAD!")
  h3('DTedit Template'),
  uiOutput('mycontacts')
  
  
)

##### Start the shiny app
shinyApp(ui = ui, server = server)

Sure. Everything is in the Github Repo: https://github.com/jienagu/DT-Editor Welcome to download it.

Fantastic! I have been learning a lot from your apps.

2 Likes

Do you think you can add a "duplicate" function to the table in case you want to add a new entry that only differs slightly?

1 Like

Thanks @noveld. Good idea!:+1: I am sure it is doable and there might be many ways to implement this feature. One way to implement is to incorporate some text searching function when you input new rows. You can check shinysky package which has some cool stuffs that might help. For example, I use text search in Name input, so when I type "J", there is my name in options and I don't have to type everything. It is useful when adding a new entry that only differs slightly.

I encountered a problem after trying to save changes to the table when using this app on my Android tablet. I got stuck in some sort of UI loop. Perhaps one of the components doesn't work so well on a tablet sized screen.

@DoughnutNZ, I try it in my ios phone and can I double check whether the issue you encountered is to scroll (right or left) the pop-up Modification page in your tablet sized screen? If so, it might be related to the modalDialog() function ( modal dialog UI) of shiny. There are some alternative R package such as shinyBS that has the same functionality to build the pop-up page. :slight_smile:

A post was split to a new topic: shinysky package is not available (for R version 3.5.2).

I would like to share the DT Editor shiny module for anyone who want to use this app for their own dataset. Repo: https://github.com/jienagu/DT_editor_shiny_module

  • This repo utilize shiny module that can fit for any data.table. You just need to create your data.table and load it to the same location of your shiny app as note.rds.
  • Currently, I am working on an elegant way to handle Date format so please convert any date col to character/factor before you load the data.table to this app`
1 Like