Search code examples
rshinyshiny-servershinydashboarddt

Factor dropdown filter in DT::datatable in shiny dashboards not working


Is it just me or is it a bug that if i have a factor column and I add filter with DT, the dropdown get cut-off in shiny dashboard.

I am using mtcars as an example and I make cyl as a factor. (the numeric slider filter works fine, but the factor filter dont). Here is the code and the screen shot.

## app.R ##
library(shinydashboard)
library(dplyr)


mtcars$cyl <- as.factor(mtcars$cyl)

ui <- dashboardPage(
  dashboardHeader(title = "Simple Dashboard"),
  ## Sidebar content
  dashboardSidebar(sidebarMenu(
    menuItem(
      "Dashboard", tabName = "dashboard", icon = icon("dashboard")
    ),
    menuItem("Widgets", tabName = "widgets", icon = icon("th"))
  )),
  ## Body content
  dashboardBody(tabItems(
    # First tab content
    tabItem(tabName = "dashboard",
            fluidRow(
              box(plotOutput("plot1", height = 250)),

              box(
                title = "Controls",
                sliderInput("slider", "Number of observations:", 1, 100, 50)
              )
            )),

    # Second tab content
    tabItem(tabName = "widgets",
            fluidRow(DT::dataTableOutput('items_dt')))
  ))
)

server <- function(input, output) {
  set.seed(122)
  histdata <- rnorm(500)

  output$plot1 <- renderPlot({
    data <- histdata\[seq_len(input$slider)\]
    hist(data)
  })

  output$items_dt = DT::renderDataTable(
    mtcars,
    filter = 'bottom',
    options = list(scrollX = TRUE)
  )
}

shinyApp(ui, server)

Factor filters get cut-off

Numeric sliders work fine


Solution

  • It seems to be a bug in shiny dashboards with DT. Reported https://github.com/rstudio/DT/issues/230