DT
DT copied to clipboard
Capturing `input$*_cell_edit` of a top level-rendered `DT` for observation/reaction in a module namespace?
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
- [X] I have fully read the issue guide at https://yihui.org/issue/.
- [X] 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.
- [X] 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.