Search code examples
rjsonshinydatatable

Warning: invalid JSON response using datatable and inside shiny app


I'm building a shiny app that displays an editable table with DT::dataTableOutput. Both displaying and editing seems to work, but I keep recieving the alert warning of invalid JSON response everytime time I edit a cell and press Enter.

I've tried to write a reproducible example and got the same alert, plus another saying that can't find an index. Here's the code.

library(shiny)
library(DT)

df <- data.frame(
  player = c("Vishy", "Magnus", "Caruana", "Nepo"),
  title = rep("GM", 4),
  age = c(50, 30, 28, 29)
)

ui <- fluidPage(
  DT::dataTableOutput("table")
)

server <- function(input, output, session) {

  react_df <- reactiveVal(df)
  
  output$table <- DT::renderDataTable({
    req(react_df())
    datatable(isolate(react_df()),
              selection = "none",
              editable = list(target = "cell", disable = list(columns = 0:1)))
  }, server = FALSE)

  proxy_df <- dataTableProxy("table")
  
  observeEvent(input$table_cell_edit, {
    info <- input$table_cell_edit
    react_df(editData(react_df(), info, proxy_df, resetPaging = FALSE))
  })  

}

shinyApp(ui, server)

Solution

  • I was having the same problem, changing the parameter server from 'FALSE' to 'TRUE' in datatable function solved it.