我有一个数据表,它正在使用DT:: rendertableOutput
在我闪亮的仪表板上呈现。这些列是A
、B
、C
、D
。现在,我只想在打开这个闪亮的应用程序时只显示列A
和B
,然后如果我单击显示的datatable上的特定行,我需要弹出一个弹出,它在列C
和D
中显示同一行的数据。
以下是我的数据框架:
> df
A B C D
A1 B1 C1 D1
A2 B2 C2 D2
条件:
A
和B
。row 1
时,row 1
的列C
和D
将显示为具有close
按钮的弹出窗口。在显示其他行时,此操作同样继续。发布于 2017-08-14 13:25:55
让我们尝试将其添加到服务器代码中。本质上,我们触发了一个模态对话框,当您选择一个特定的行时,它会出现,并显示其余的数据。
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())
})
https://stackoverflow.com/questions/45673948
复制相似问题