rshinytabsshinydashboardbs4dash

How to keep DT table borders within tabBox()


I want to control the position of a DT table output within a tabBox():

This example app gives this:

library(shiny)
library(bs4Dash)
library(DT)

shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(),
    sidebar = dashboardSidebar(),
    body = dashboardBody(
      tabBox(
        id = "tabset1",
        height = 750,
        tabPanel("Hello", "This is the hello tab",
                 DT::DTOutput("myTable")
                 ))
      )
  ),
  server = function(input, output, session) {
    output$myTable <- DT::renderDT({
      DT::datatable(
        mtcars) 
    })
  }
)

enter image description here

As you can see the DT table is exceeding the borders of tabBox panel. How can we force DT to keep inside tabBox panel (width and height).

Desired output: enter image description here


Solution

  • We can also use scrollX option:

    output$myTable <- DT::renderDT({
      DT::datatable(
        mtcars,
        options = list(
          scrollX = TRUE
        )
      )
    })