Shiny app with editable DT, two features producing same error: Warning: Error in split.default: first argument must be a vector

Hi, I am having a problem with a shiny app. The app calls a module editr which enables the user to edit a datatable and then to store those edits by replacing the unedited object. (Minrep at the bottom)

The first problem:

I tried to make it able to accept more than one cell-edit per go, I did this by replacing the #OLD code with the #NEW code (see labelled as such in minrep at the bottom):

editTable <- reactive({
                datatable(
                    reactives$input,
                    editable = T,                           #OLD 
                    #editable = list(target = "all"), #NEW
                    rownames = F
                )
            })

When the app is used with the #NEW code, it produces the following error when the "Edit" button is pressed after making an edit:

Warning: Error in split.default: first argument must be a vector

The second problem:

arises when I try to make the app bookmarkable via the server. When I use the app with the bookmark feature and the #OLD code, I can still make edits to the table, BUT once I make such an edit and attempt to transfer this edit into a new session e.g. by copying and pasting the link into the browser, I get a pale view of the app which is semi interactive but has content missing e.g. the table. If I then look in the console of RStudio, it produces the same error as with the #NEW code:

Warning: Error in split.default: first argument must be a vector

This problem is very very weird to me I can see no way out of it and there are very few discussions of similar problems. I am open to any suggestions because this has held me up massively. If there is a better way of doing this that requires a total overhaul id be keen to hear it! Many thanks :slight_smile:

The following is a minrep with the #NEW and #OLD markings.

library(tidyverse)
library(DT)

editrUI <- function(id, labelDo, labelUndo) {
    ns <- NS(id)
    tagList(
        dataTableOutput(ns("out")),
        actionButton(
            inputId = ns("do"),
            label = labelDo
        ),
        actionButton(
            inputId = ns("undo"),
            label = labelUndo
        )
    )
}

editrServer <- function(id, dataFrame) {
    moduleServer(
        id,
        function(input, output, session){
            
            reactives <- reactiveValues()
            
            reactives$input <- NULL
            
            observe({
                reactives$input <- dataFrame
            })
            
            
            editTable <- reactive({
                datatable(
                    reactives$input,
                    editable = T,                           #OLD 
                    #editable = list(target = "all"), #NEW
                    rownames = F
                )
            })
            
            output$out <- renderDataTable(
                editTable()
            )
            
            observeEvent(input$do , {
                reactives$input <<- editData(reactives$input, input$out_cell_edit, rownames = F) 
            })
            
            observeEvent(input$undo , {
                reactives$input <- dataFrame
            })
            
            return(reactive({reactives$input}))
        }
    )
}


################################################################################


library(shiny)

a <- 1:5
df <- tibble(a, a*2)

ui <- function(request) { 
    fluidPage(
        editrUI(id = "id", labelDo = "Edit", labelUndo = "Undo"),
        bookmarkButton()
    )
}


server <- function(input, output) {
    editrServer(id = "id", dataFrame = df)
}

# Run the application 
shinyApp(ui, server, enableBookmarking = "server")

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