DillonHammill / DataEditR

An Interactive R Package for Viewing, Entering Filtering and Editing Data
https://dillonhammill.github.io/DataEditR/
381 stars 40 forks source link

Print edited table in shiny app #51

Closed chabrault closed 2 years ago

chabrault commented 2 years ago

Hello, First, thanks for this beautiful package, it will help me a lot! I'm building a Shiny App using your package and I'm struggling to figure out how to extract and save the table once edited. I reproduced below a quick Shiny App:

library(DataEditR)

if(interactive()) {
  ui <- fluidPage(
    dataOutputUI("output-1"),
    dataEditUI("edit-1"),
    tableOutput("tab")
  )

  server <- function(input, output, session) {
    x <- data.frame(Age = c(10, 20, 1000), Weight = c(120, 131, 111))
    data_edit <- dataEditServer("edit-1",data = x)
    edited <- dataOutputServer("output-1",data = data_edit)
    output$tab <- renderTable(edited())
  }
  shinyApp(ui, server)
}

In this example, there is no table output and it throws the following error: Warning: Error in renderFunc: argument "shinysession" is missing, with no default. I tried the following alternative: output$tab <- renderTable(edited) but it was not working either. Do you know how to deal with that?

DillonHammill commented 2 years ago

@chabrault, not exactly sure where the error is coming from - it seems external to DataEditR. Anyways, I normally resort to using reactiveValues() for these sorts of tasks and it works in your case:

library(DataEditR)

if(interactive()) {
  ui <- fluidPage(
    dataOutputUI("output-1"),
    dataEditUI("edit-1"),
    tableOutput("tab")
  )

  server <- function(input, output, session) {
    values <- reactiveValues(
      data = data.frame(Age = c(10, 20, 1000), Weight = c(120, 131, 111))
    )
    data_edit <- dataEditServer("edit-1", data = values$data)
    observe({
      values$data <- data_edit()
    })
    edited <- dataOutputServer("output-1",data = values$data)
    output$tab <- renderTable(values$data)
  }
  shinyApp(ui, server)
}