2017-08-14 7 views
0

光沢のあるダッシュボードでDT:: rendertableOutputを使用してレンダリングされているデータテーブルがあります。列はA,B,C,Dです。今度は、ABという文字列をShinyアプリケーションを開くときに表示したいのですが、表示されたデータテーブルの特定の行をクリックすると、同じ行のデータが列CDに表示されます。光沢のあるダッシュボードでポップアップモーダルダイアログ/ポップアップを表示する

以下

は私のデータフレームである:

> df 
    A   B  C  D 
    A1  B1  C1  D1 
    A2  B2  C2  D2 

条件:光沢のあるアプリの開口部に

  1. 、列のみABが表示されます。
  2. 表示されるデータの row 1は、その列 Crow 1Dクリックする
  3. closeボタンがあるポップアップとして表示されます。これは他の行が表示されているときも同様です。

答えて

2

これをサーバーコードに追加してみましょう。基本的には、特定の行を選択して残りのデータを表示するときに、モーダルダイアログボックスを表示します。

require(dplyr) 

#Here's our table: 
tbl <- data.frame(A= c('A1','A2'), 
      B= c('B1','B2'), 
      C = c('C1','C2'), 
      D = c('D1','D2')) 

#The dt output code 
output$my_table <- renderDataTable({ 
     datatable(tbl %>% select(A,B),selection='single') 
}) 

#reactive table based on the selected row 
tbl_reactive <- reactive({ 
     tbl[as.numeric(input$my_table_rows_selected[1]),] 
}) 

#here's the table displayed in our modal 
output$modal_table <- renderDataTable({ 
     tbl_reactive() 
}) 

#our modal dialog box 
    myModal <- function(failed=FALSE){ 
     modalDialog(
    dataTableOutput('modal_table'), 
     easyClose = TRUE 

     ) 
    } 

#event to trigger the modal box to appear 
observeEvent(input$my_table_rows_selected,{ 

    showModal(myModal()) 

}) 
+0

ソリューションありがとうございます!コードは部分的に機能します。アプリの開始時に 'col A'と' col B'だけを表示でき、onclickがポップアップ表示されます。これらはすべて私が望んでいたのとまったく同じように働いています。しかしポップアップの中には 'col C'と' col D'のデータはありません。私が呼び出す必要のあるライブラリはどれですか? – Tareva

+0

ありがとう、うまくいっています。問題は、 'dataTableOutput( 'modal_table')'に不必要なスペースがあったことです。 – Tareva

関連する問題