【问题标题】:Factor dropdown filter in DT::datatable in shiny dashboards not working闪亮仪表板中 DT::datatable 中的因子下拉过滤器不起作用
【发布时间】:2016-05-12 03:41:42
【问题描述】:

仅仅是我还是一个错误,如果我有一个因子列并且我添加了带有 DT 的过滤器,下拉列表在闪亮的仪表板中被截断。

我以 mtcars 为例,我将 cyl 作为一个因素。 (数字滑块过滤器工作正常,但因子过滤器不行)。这是代码和屏幕截图。

## 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)

【问题讨论】:

    标签: r shiny shiny-server shinydashboard dt


    【解决方案1】:

    通过不使用 scrollX 或 scrollY 并在顶部放置过滤器,我在下拉菜单中获得了更好的运气。

    B^(

    【讨论】:

    • 在仪表板中,如果您将过滤器放在顶部,所有过滤器都会被截断,即使是数字滑块:(
    【解决方案2】:

    这似乎是带有 DT 的闪亮仪表板中的一个错误。举报https://github.com/rstudio/DT/issues/230

    【讨论】:

      【解决方案3】:

      我通过将数据框的列类型更改为因子来解决它:df[, 'X1']

      【讨论】:

        猜你喜欢
        • 2017-11-09
        • 2016-12-09
        • 2021-12-19
        • 1970-01-01
        • 2020-10-27
        • 2018-05-18
        • 1970-01-01
        • 2016-08-18
        • 2015-04-22
        相关资源
        最近更新 更多