Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editable DT on Shiny Server: Edits through coerceValue/replaceData operational, yet forces JSON Error when Server = FALSE passed. #598

Closed
HitKnit opened this issue Sep 28, 2018 · 3 comments

Comments

@HitKnit
Copy link

HitKnit commented Sep 28, 2018

Dear DT community.

I have a fully operational Shiny app in which the user edits a DT object, after which some dependent summary statistics are displayed. When passing the client-side processing option to renderDT (server = F) in order to speed things up, a user edit of the DT is implemented correctly with the dependent summary stats updating, however the browser throws the following (dismissable) error;

DataTables warning: table id=DataTables_Table_5 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

I have browsed and posted a thorough query on SO which remains unresolved;
https://stackoverflow.com/questions/52519367/dt-editing-in-shiny-application-with-client-side-processing-server-f-throws

REPRODUCIBLE EXAMPLE (Only allowing edits in Col 1), Note that changing server = TRUE yields fully operational application

library(shiny)
library(DT)

dt = data.frame(V1 = c(1,2), V2 = c(3,4))

server <- function(input, output, session) {
    
val = reactiveValues(mat = data.table(dt))
    
output$testDT = renderDataTable({
            DT::datatable(val$mat, editable = TRUE)
}, server = FALSE)
    
proxy = dataTableProxy('testDT')

observeEvent(input$testDT_cell_edit, {
  
  info = input$testDT_cell_edit
  
  str(info)
  
  i = info$row
  j = info$col
  v = info$val
  
  if (j == 1){
    
  val$mat$V1[i] = DT::coerceValue(v, val$mat$V1[i])
  replaceData(proxy, val$mat, rownames = FALSE)
  
  }
  
})
    
    
}

ui <- fluidPage(
  dataTableOutput('testDT') 
)

shinyApp(ui, server)
@shrektan
Copy link
Collaborator

Probably it's not documented clearly. It has nothing to do with the editing. It's because replaceData() calls reloadData(), which requires the server-side processing mode. See ?reloadData().

reloadData() only works for tables in the server-side processing mode, e.g. tables rendered with renderDataTable(server = TRUE). The data to be reloaded (i.e. the one you pass to dataTableAjax()) must have exactly the same number of columns as the previous data object in the table.

@HitKnit
Copy link
Author

HitKnit commented Sep 29, 2018

Probably it's not documented clearly. It has nothing to do with the editing. It's because replaceData() calls reloadData(), which requires the server-side processing mode. See ?reloadData().

reloadData() only works for tables in the server-side processing mode, e.g. tables rendered with renderDataTable(server = TRUE). The data to be reloaded (i.e. the one you pass to dataTableAjax()) must have exactly the same number of columns as the previous data object in the table.

Thank you for your answer. So I suppose at this stage it is not possible to implement an editable DT with client-side processing when replaceData has to be called in that process. Feel free to paste your reply into the SO thread as well and I'll approve it.

@shrektan
Copy link
Collaborator

shrektan commented Oct 2, 2018

I've pasted the reply on the SO 😺 .

Since the issue has been solved, would you please close this issue?

Thanks.

@HitKnit HitKnit closed this as completed Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants