如何跟踪可反应的嵌套表?

How to keep track of nested tables in reactable?

我有一个问题,我不太确定如何解决。考虑这个闪亮的应用程序示例:

library(shiny)
library(reactable)
library(dplyr)


random_requests <- data.frame(
    Request_ID = c(1,2,3,4,5),
    Status = c("Accepted", "Accepted", "Accepted", "Declined", "Created")
)

random_samples <- data.frame(
    Request_ID = c(1,1,1,2,3,3,4,5),
    Sample_ID = c(1,2,3,4,5,6,7,8),
    statistics = sample(1:100, 8)
)


# Define UI for application 
ui <- fluidPage(
    
   selectInput(inputId = "select",
               label = "Select a choice:",
               choices = c("All", "Accepted", "Declined", "Created")),
    hr(),
    reactableOutput(outputId = "table")
)

# Define server logic 
server <- function(input, output) {
    
    
    data <- eventReactive(input$select, {
        if(input$select == "All"){
            random_requests
        } else {
            random_requests %>%
                filter(Status == input$select)
        }
    })
    
    
    output$table <- renderReactable({
        
        reactable(
            data(),
            details = function(index, name){
                htmltools::div(
                    reactable(random_samples[random_samples$Request_ID == index, ])
                )
            }
            )
    })
}

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

我想使用 expandable rows feature of reactable。主 table 应该显示请求,然后当您展开该行时,子 table 应该显示与该特定请求关联的样本。当 table 是静态的时,这很好用,但是当我使用下拉列表进行过滤时,它的行为并不像预期的那样。当前子 table 按行索引匹配,因此当我过滤 table 时,示例子 table 与正确的请求不匹配。

我怎样才能实现这个功能?也就是说,link random_requests 和 random_samples table 如何在 details 函数中通过 Request_ID 使其在过滤时起作用?

谢谢! -凯尔

软件包开发人员 Greg Lin 的回答:https://github.com/glin/reactable/issues/199#issuecomment-933003834

此功能可以通过将可响应代码修改为:

来实现
output$table <- renderReactable({
    
    reactable(
      data(),
      details = function(index, name){
        request_id <- data()[index, "Request_ID"]
        htmltools::div(
          reactable(random_samples[random_samples$Request_ID == request_id, ])
        )
      }
    )
  })