Reputation: 24845
When I try to use DTOutput()
and renderDT()
within bslib
framework, the rendering of those tables is very slow.
Example app with bslib
:
library(shiny)
library(DT)
library(data.table)
library(bslib)
dt= mtcars |> as.data.table()
ui <- page_sidebar(
layout_columns(
card(card_header('Gear', class="bg-primary"), DTOutput("gear")),
card(card_header('Carb', class="bg-primary"), DTOutput("carb")),
card(card_header('AM', class="bg-primary"), DTOutput("am")),
col_widths = c(4,4,4)
),
sidebar = sidebar(
selectInput("cyl", "Cylinder", choices=dt[, unique(cyl)])
)
)
server <- function(input, output, session) {
output$gear <- renderDT(dt[cyl==input$cyl, .N, gear])
output$carb <- renderDT(dt[cyl==input$cyl, .N, carb])
output$am <- renderDT(dt[cyl==input$cyl, .N, am])
}
shinyApp(ui, server)
I can speed this up dramatically, in one of three ways:
renderTable()
and tableOutput()
style='auto'
(the default in datatable()
) to one of the other options ('default', 'bootstrap','bootstrap4', etc)library(shiny)
library(DT)
library(data.table)
dt= mtcars |> as.data.table()
ui <- fluidPage(
sidebarLayout(
sidebarPanel(selectInput("cyl", "Cylinder", choices=dt[, unique(cyl)]),width=2),
mainPanel = mainPanel(
fluidRow(column(4, DTOutput("gear")),column(4, DTOutput("carb")),column(4, DTOutput("am"))), width=10
)
)
)
server <- function(input, output, session) {
output$gear <- renderDT(dt[cyl==input$cyl, .N, gear])
output$carb <- renderDT(dt[cyl==input$cyl, .N, carb])
output$am <- renderDT(dt[cyl==input$cyl, .N, am])
}
shinyApp(ui, server)
what is going on with bslib
and DT
and style='auto'
such that rendering speed suffers when used in conjunction? What can be done about it, if anything?
Upvotes: 1
Views: 52