Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capturing input$*_cell_edit of a top level-rendered DT for observation/reaction in a module namespace? #1150

Open
3 tasks done
r-cheologist opened this issue Aug 30, 2024 · 0 comments

Comments

@r-cheologist
Copy link

This is aan adapted re-posting at the source of DT of this question. I remain stuck.

I am aiming to extend this example, which implements a shiny-rendered DT including the capture of any edits done to the rendered data.

My version is to split off datatable handling into a shiny module, but render the result in the toplevel namespace. In the above stackexchange.com issue, I have gotten introduced to session[["userData"]] and based on that manage to display the module-provided DT on the top namespace level.

I fail, however, to capture the input$*_cell_edit in a corresponding session[["userData"]] object for further reaction in the module. How would I go about this?

Minimal code demonstrating (the rendering side of) the issue follows:

requireNamespace("shiny")
requireNamespace("DT")

datatableUI <- function(id = "datatable")
{
  shiny::tagList(shiny::sidebarPanel(shiny::uiOutput("LocalTextPlaceholder")))
}

ui <- shiny::fluidPage(
  shiny::titlePanel("Module Version"),
  shiny::sidebarLayout(
    shiny::sidebarPanel(shiny::uiOutput("TextPlaceholder")),
    shiny::mainPanel(
      datatableUI(),
      shiny::uiOutput("DTPlaceholder"))))

datatableServer <- function(id = "datatable")
{
  shiny::moduleServer(id, function(input, output, session)
  {
    session$userData$DT <- DT::datatable(
      iris, selection = 'none', editable = TRUE, rownames = TRUE, extensions = 'Buttons',
      options = list(
        paging = TRUE, searching = TRUE, fixedColumns = TRUE,   autoWidth = TRUE, ordering = TRUE,
        dom = 'Bfrtip', buttons = c('csv', 'excel')),
      class = "display")
  })
}

server <- function(input, output, session) {
  datatableServer()
  shiny::observeEvent(
    session$userData$DT,
    {
      output$DTPlaceholder <- shiny::renderUI(session$userData$DT)
    }
  )
}

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

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant