DT - Remove row

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)
  1. It uses this piece of documentation datatable to remove the row
  2. 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.

Hi John! Setting server = FALSE in renderDT made this work for me...

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")
  }, server = FALSE)
}

shinyApp(ui, server)

This topic was automatically closed 7 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.