Hello!

I'd like to have an editable table which would allow the user to filter for certain values and edit them without resetting the filtering context. Somehow both: search and filtering do not work (the table "unfilters") and I already tried all different options in shiny/ DT and wasn't able to find any reference online for that.

I assume the problem must be somehow related to the reactivity of my solution but can't nail it down. Has anyone come across a similar issue and was able to overcome?

A small example below:

library(shiny)
library(DT)
library(tidyverse)

options(shiny.reactlog = TRUE)

shinyApp(
  ui = fluidPage(
    actionButton(
      inputId = "go",
      label = "Update"
    ),
    DTOutput('x1')
  ),
  server = function(input, output, session) {
    
    evt_go_iris <- eventReactive(input$go, {
      x = iris
      x$Date = Sys.time() + seq_len(nrow(x))
      x <- as.data.frame(x) %>% 
        slice(1:20)
    })
    
    rec_val = reactiveValues(df = NULL)
    
    observe({
      rec_val$iris <- evt_go_iris()
    })
    
    output$x1 = DT::renderDataTable({datatable(rec_val$iris, rownames = FALSE, editable = TRUE, filter = "top")}) 
    
    proxy = DT::dataTableProxy("x1")
    
    observeEvent(input$x1_cell_edit, {
      info = input$x1_cell_edit
      rec_val$iris <<- editData(rec_val$iris, info, "proxy", rownames = FALSE, resetPaging = FALSE)
    })
  }
)

I think you want proxy, not "proxy". Also I think you have a few unnecessary names/objects floating around here, this is how I'd do it:

library(shiny)
library(DT)
library(tidyverse)

options(shiny.reactlog = TRUE)

shinyApp(
  ui = fluidPage(
    actionButton(
      inputId = "go",
      label = "Update"
    ),
    DTOutput('x1')
  ),
  server = function(input, output, session) {
    
    data <- reactiveVal(iris)
    
    data_go <- eventReactive(input$go, {
      data() %>%
        mutate(Date = Sys.time() + seq_len(nrow(.))) %>%
        slice(1:20)
    })
    
    output$x1 <- DT::renderDataTable({
      datatable(data_go(), rownames = FALSE, editable = TRUE, filter = "top")
    }) 
    
    proxy <- DT::dataTableProxy("x1")
    
    observeEvent(input$x1_cell_edit, {
      ed <- editData(
        data_go(), input$x1_cell_edit, 
        proxy, rownames = FALSE, resetPaging = FALSE
      )
      data(ed)
    })
  }
)
1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.