问题
I have a requirement to show 2 datatables in 2 different tabs in a shiny application. One is a simple datatable whereas the other uses the rowgroup extension of DT package. When I'm using tabs to display both the datatables, the rowgroup function doesnt seem to work.
library(shiny)
library(DT)
library(shinyjs)
ui <- fluidPage(
dashboardBody(
fluidRow(
tabBox(width = "100%",
tabPanel("Table 1",
fluidRow(
column(12, withSpinner(DTOutput("my_table2",height="600px")))
)
),
tabPanel("Table 2",
fluidRow(
column(12, withSpinner(DTOutput("my_table1",height="600px")))
)
)
)
)
)
)
server <- function(input, output) {
output$my_table1<-DT::renderDataTable({
datatable(mtcars[1:15,1:5],
extensions = 'RowGroup',
options = list(rowGroup = list(dataSrc=c(3)),
pageLength = 20),
callback = JS("
$('#DataTables_Table_0 tbody').on('click', 'tr.group', function () {
var rowsCollapse = $(this).nextUntil('.group');
$(rowsCollapse).toggleClass('hidden');
});"))
})
output$my_table2<-DT::renderDataTable({
datatable(mtcars[1:15,1:5],rownames = FALSE,
options = list(
order=list(list(1,'asc'),list(2,'asc')),
scrollX = TRUE,
pageLength = 100,
lengthMenu = c(10, 20, 100),
searching = TRUE)) %>%
formatStyle(0, target= 'row',color = 'black', backgroundColor = 'silver',
fontWeight ='normal', lineHeight='100%')
})
}
shinyApp(ui = ui, server = server)
But if I display the datatable with rowgroup in 1st tab, its working fine. But my requirement is to display the table with rowgroup in Tab 2.
Can someone please help
来源:https://stackoverflow.com/questions/60401871/rowgroup-function-not-working-when-there-are-multiple-datatable-to-be-displayed