DillonHammill / DataEditR

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

How to use all modules inside a shiny app #29

Closed ShinyFabio closed 2 years ago

ShinyFabio commented 3 years ago

Hi Dillon, I'm developing another shiny app and now I need all the modules (filter,select,sync and so long). Could you explain me how I can use all the modules together? For example the correct order of the functions in the server part. I searched in every help and tried some combinations but nothing seems to work. I wrote this example but it doesn't work.

  library(shiny)
  library(rhandsontable)
  library(shinyjs)
  library(DataEditR)
  library(DT)

  ui <- fluidPage(
    useShinyjs(),
    DTOutput("test"),
    DTOutput("test2"),
    actionButton("editinternal", icon("edit")),
    tags$head(tags$style("#upinternalmodal .modal-dialog{ width:1300px}")),
    tags$head(tags$style("#upinternalmodal .modal-body{ min-height:1000px}")),
    shinyBS::bsModal("upinternalmodal", "Edit data", trigger = "editinternal", size = "large",
        dataFilterUI("filter1"),
        dataSyncUI("sync1"),
        DataEditR::dataOutputUI("output_internal_edit"),
        DataEditR::dataEditUI("edit1")
    )
  )

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

    data = reactive(return(ggplot2::mpg))

    output$test = renderDT(data())

    data_edit  <- DataEditR::dataEditServer("edit1", data = data(), col_names = FALSE)

    filtered = dataFilterServer("filter1", data = data_edit())

    data_sync <- DataEditR::dataSyncServer(
      "sync1",
      data = data(),
      data_subset = filtered,
    )

    output$test2 = renderDT({
      req(data_sync())
      data_sync()
    })

    DataEditR::dataOutputServer("output_internal_edit", data = data_sync())

  }

  shinyApp(ui, server)
DillonHammill commented 3 years ago

@ShinyFabio the best thing you can do is look at the way that I have written the data_edit() function it should give you some hints as to how everything fits together.