DT-Editor icon indicating copy to clipboard operation
DT-Editor copied to clipboard

Unable to save updated data frame as .rds file with below replicated r shiny app

Open sound118 opened this issue 1 year ago • 0 comments

I got below replication of R shiny app which is simpler version of yours, when run it and edit the last column of iris data frame, the app always give me this error message: Warning: Error in <<-: invalid (NULL) left side of assignment Could you please help me to debug it? Thanks.

library(shiny) library(DT)

ui <- fluidPage( DTOutput("iris_table") )

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

create a reactive copy of iris data frame

iris_data <- reactiveVal(iris)

render the data table with editable option for the last column

output$iris_table <- renderDT({ datatable(iris_data(), editable = list(target = "column", disable = list(columns = c(0:4)))) })

update the iris data frame when the user edits the last column

observeEvent(input$iris_table_cell_edit, { info <- input$iris_table_cell_edit str(info) i <- info$row j <- info$col v <- info$value iris_data()[i, j] <<- DT::coerceValue(v, iris_data()[i, j])

# save the updated iris data frame as iris_updated.rds file in a directory
saveRDS(iris_data(), file = "iris_updated.rds")

}) }

shinyApp(ui, server)

sound118 avatar Aug 05 '23 15:08 sound118