rendertDT() on reactive objects

Hi Community!

I have a question regarding editable data input: I would like to load in some data from csv-file, extract given informations (e.g. colnames) and present these information as modified dataframe to user.
User should then edit table and finally the table will be used for further analysis.

Now I'm facing the following problem: When I'm working on a static file (such as cars, iris, ...) everything works well (e.g. as shown here: https://yihui.shinyapps.io/DT-edit/). However, since I'm working a rawData(), which is based on eventReative() it does not work, because I cannot really use replaceData() with this data structure.

I get two following errors:

  1. Warning: Error in <<-: invalid (NULL) left side of assignment [No stack trace available]

If I change one value in the editable table to "ABC":
2) Warning in DT::coerceValue(v, rawData()[i, j]): New value ABC not in the original factor levels

Would be nice if someone could help me :slight_smile:
Best regards!

library(shiny)
library(DT)

ui <- fluidPage(
  fileInput("csvFile", "Input File!"),
  DTOutput("edit")
)

server <- function(input, output, session) {
  rawData <- eventReactive(input$csvFile, {
    x <- read.csv(input$csvFile$datapath)
    
    data.frame(experiment = colnames(x[,-1]),
               condition = rep("NA", length(colnames(x[,-1]))))
  })
  
  
  output$edit <- renderDT(rawData(), editable=TRUE)
  
  proxy = dataTableProxy('edit')
  
  observeEvent(input$edit_cell_edit, {
    info = input$edit_cell_edit
    str(info)
    i = info$row
    j = info$col
    v = info$value
    rawData()[i, j] <<- DT::coerceValue(v, rawData()[i, j])
    replaceData(proxy, rawData(), resetPaging = FALSE) 
  })
}

shinyApp(ui, server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.