簡體   English   中英

閃亮的 DT 包 dataTableOutput 不允許觀察監視選定的行

[英]shiny DT package dataTableOutput does not allow observe to monitor selected rows

我有一個閃亮的界面,我有兩個 DT 表。 我希望第二個表基於反應式表達式(有效)的輸出與第一個表中選定的數據相結合來呈現。 但是,當我為第二個 DT renderTable 表達式編寫觀察者時,整個觀察者不會對選定行的變化做出反應。 我猜這是因為 input$table_selected_rows 沒有在代碼中定義,而是以某種方式固有的 DT 包(我只定義了 input$table)。 第二個表的代碼是

row<-reactive({
    print("check")
    input$table_selected_rows
  })
  observe({
    a=row()
    print(a)
    if(length(a)>0){
      res=dtf()
      ID=res[a,]
      res=res[which(res$ID==ID),]
      output$table2=DT::renderDataTable(dplyr::distinct(res),
                                        selection=list(mode="single",target="row"))
      }

  })
  observe({
  row()
  })

在上面的代碼中,“check”只在代碼初始化時打印一次,而不是在我從會話中的第一個表中選擇行時打印。 我如何強制閃亮監視 input$table_selected_rows 以便第二個表對第一個表有反應?

您的代碼中的問題是,您切換了輸入名稱:

table_selected_rows應該是table_rows_selected 請參閱此處的第 2.1.1 章。

這是一個簡單的可重現示例:

library(shiny)
library(DT)
library(datasets)

ui <- fluidPage(
  DTOutput("Tab1"),
  DTOutput("Tab2")
)

server <- function(input, output, session) {
  output$Tab1 <- renderDT({iris}, selection=list(mode = "single", target = "row"))
  row <- reactive({input$Tab1_rows_selected})
  output$Tab2 <- renderDT({data.frame(row())})
}

shinyApp(ui, server)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM