R 筛选datatable以仅列出选定行

R 筛选datatable以仅列出选定行,r,shiny,dt,R,Shiny,Dt,是否有方法将数据表筛选到所选行 我有一个巨大的数据框,有20000行,如果搜索并选择一些行,这有点棘手。如果要取消选择,则必须浏览列表并搜索已单击的行或重置完整选择 我认为最好只将表筛选到选定的行,用户可以再次取消选择这些行 library(shiny) library(DT) ui <- shinyUI( fluidPage( DT::dataTableOutput("name_table") ) ) server <- function(input,

是否有方法将
数据表
筛选到所选行

我有一个巨大的数据框,有20000行,如果搜索并选择一些行,这有点棘手。如果要取消选择,则必须浏览列表并搜索已单击的行或重置完整选择

我认为最好只将表筛选到选定的行,用户可以再次取消选择这些行

library(shiny)
library(DT)

ui <- shinyUI(
  fluidPage(
        DT::dataTableOutput("name_table")
  )
)

server <- function(input, output, session) {
  output$name_table <- DT::renderDataTable({
    DT::datatable(mtcars,
                  options=list(pageLength=5),
                  selection=list(selected=c(1,3,32)))
  })
  name_proxy = DT::dataTableProxy('name_table')
}

shinyApp(ui, server)
库(闪亮)
图书馆(DT)

ui我不知道是否可以只使用一个表,但通过创建包含所有选定项的第二个表,并允许根据您(取消)在第二个表中选择的内容更新第一个表中的选择,可以获得所需的效果。 由于表的反应性导致了问题,我在更新选择的周围添加了一个
actionButton
,但我认为没有它应该是可行的

当前,第二个表始终显示在第一个表中选择的所有行。如果要修剪选择,请取消选择第二个表中的一行,然后按
更新选择
按钮

library(shiny)
library(DT)

ui <- shinyUI(
  fluidPage(
    DT::dataTableOutput("name_table"),
    DT::dataTableOutput("selected_table"),
    actionButton("selectbutton", label = "Update selections")
  )
)

server <- function(input, output, session) {
  mtcarsmod <- mtcars # We need a table with the row numbers as a column
  mtcarsmod$Rownr <- 1:nrow(mtcars)

  output$name_table <- DT::renderDataTable({
    DT::datatable(mtcarsmod,
                  options=list(pageLength=5),
                  # Have those rows selected that show up in the selected_table
                  selection= list(selected=
                                    c(1,3,32)
                  )
    )
  })

  name_proxy <- DT::dataTableProxy('name_table') # Proxy to use for updating the selection

  mtcars_selected <- reactive(mtcarsmod[input$name_table_rows_selected,]) # The selected options from the first table

  output$selected_table <- DT::renderDataTable({
    try(DT::datatable(mtcars_selected(),
                      options=list(pageLength=5),
                      # have all entries selected
                      selection= list(selected=
                                        1:nrow(mtcars_selected()))
    ))
  })


  observeEvent(input$selectbutton,  # When you press the button update the selections in the first table
               selectRows(name_proxy, mtcars_selected()[input$selected_table_rows_selected,"Rownr"])
  )

}

shinyApp(ui, server)
库(闪亮)
图书馆(DT)

ui我更想寻找一种解决方案,以更新显示的数据,只显示选定的行。。。两张桌子的版本可以工作,我以前也用过,但一点都不方便……这只是不同的桌子显示的问题。例如,如果有一个包含主表的选项卡和一个包含选定表的选项卡,则切换选项卡基本上是“更新显示的数据以仅显示选定的行”对吗?也许我没有理解你想要达到的目标的一部分。