I thought I could delete a row from a DT table with:
library(DT)
library(shiny)
dat <- cars
ui <- fluidPage(
tags$head(
tags$script(
"function deleteRow(el){
$('#table')
.data('datatable')
.row(
$(el).parents('tr')
)
.remove()
.draw();
};"
)
),
DTOutput("table"),
)
server <- function(input, output){
output$table <- renderDT({
dat$delete <- "<a onclick='deleteRow(this);'>delete</a>"
datatable(dat, escape = FALSE, selection = "none")
})
}
shinyApp(ui, server)
- It uses this piece of documentation datatable to remove the row
- The instance of the datatable is retrieve using code found here
I'm not sure what is done wrong, the row is simply not removed.