2016-11-23 1 views
2

datatableを選択した行にフィルタリングする方法はありますか?選択された行だけを一覧表示するためにデータテーブルをフィルタリングする

私は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) 

したがって、私の例では、リストを1,3および32行にフィルタリングする必要があり、3つすべてを選択して選択を解除する必要があります。

私は何をしようとしているのか明確であることを願っています。

答えて

0

1つのテーブルで可能かどうかはわかりませんが、選択したすべてのエントリを含む2番目のテーブルを作成し、最初のテーブルの選択を2番目のテーブルは、あなたが望む効果を得る。 テーブルの反応性が問題を引き起こしていたので、私はactionButtonを選択の更新の周りに追加しましたが、それがなければ実行可能でなければならないと思います。

現在、2番目のテーブルは、すべての行が選択されている最初のテーブルで選択されているものを常に示します。あなたが選択をトリミングしたい場合は、第二のテーブルの行を選択解除し、私はより多くの唯一の選択された行を表示するように表示データを更新するためのソリューションを探していましたUpdate selectionsボタン

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) 
+0

を押してください... 2つのテーブルのバージョンの作品と私は前に使用しましたが、便利ではありません... – drmariod

+0

それはちょうど異なるテーブルを表示する問題です。たとえば、メインテーブルのタブと選択したテーブルのタブがある場合、切り替えタブは基本的には「選択した行のみを表示するように表示データを更新しますか?たぶん私はあなたが達成しようとしていることの一部を理解していないでしょう。 –

関連する問題