Edit Specific columns of DataTable in R

Viewed 1275

I am trying to edit the DataTable in r by using the editable=TRUE. However, i would like to edit only some specific columns of the table and not all the columns. Is that possible? The code that i am using is:

library(shiny)
library(DT)

ui <- fluidPage(
DT::dataTableOutput('population_table'),
textOutput("text")
)
server <- function(input, output, session) {
data = head(iris)
y <- reactive({
input$population_table_cell_edit
data
})
output$population_table = DT::renderDataTable(data, selection = 'none', 
editable = TRUE)

proxy = dataTableProxy('population_table')
observeEvent(input$population_table_cell_edit, {
info = input$population_table_cell_edit
str(info) #print 
i = info$row
j = info$col
v = info$value
data[i, j] <<- DT::coerceValue(v, data[i, j])
replaceData(proxy, data, resetPaging = FALSE)
})
output$text <- renderText({
y()[1, 1]
})
}
shinyApp(ui,server)
1 Answers

Maybe a little bit late, but I tried the same and only found a workaround for your problem by making an if statement, like for example if you want to change only column 3:

if(j == 3){
    data[i, j] <<- DT::coerceValue(v, data[i, j])
    replaceData(proxy, data, resetPaging = FALSE)
}else{}

At least it works for me, but I would prefer to handle it different.

Related