更改数据表中的列宽

时间:2017-01-27 22:41:05

标签: r shiny dt

我正在尝试更改DT::datatable中列的宽度,但我没有运气。根据代码here,在columnDefs中指定列宽应该是直截了当的。

但是我无法让我的列更改宽度:

library(shiny)
library(DT)

ui <- fluidPage(mainPanel(DT::dataTableOutput("test1"),
                          DT::dataTableOutput("test2"),
                          DT::dataTableOutput("test3")))

server <- function(input, output) {
  x <- structure(list(respondent = c(1847291, 1823441, 1932184, 1832521
  ), answer = c("Persia", "US", "Romainia", "Guiana"), SimilarResponse = c(NA,
                                                                           "USA", "Romania", "Guyana"), SimilarResponseUpcode = c(NA, 1,
                                                                                                                                  4, 2)), row.names = c(NA, -4L), .Names = c("respondent", "answer",
                                                                                                                                                                             "SimilarResponse", "SimilarResponseUpcode"), class = "data.frame")

  output$test1 <- DT::renderDataTable(
    x
    ,
    rownames = FALSE,
    selection = list(mode = "none"),
    options = list(autoWidth = TRUE,
                   columnDefs = list(list(
                     width = '100px', target = 3
                   )))
  )

  output$test2 <- DT::renderDataTable(
    x
    ,
    rownames = FALSE,
    selection = list(mode = "none"),
    options = list(autoWidth = TRUE,
                   columnDefs = list(list(
                     width = '100px', targets = 3
                   )))
  )

  output$test3 <- DT::renderDataTable(
    x
    ,
    rownames = FALSE,
    selection = list(mode = "none"),
    options = list(autoWidth = TRUE,
                   columnDefs = list(list(
                     width = '20px', targets = 0:3
                   )))
  )


}

shinyApp(ui = ui, server = server)

所有三个表都无法更改宽度。当我从DT宽度变化中运行示例时,所以我对我做错了什么很困惑。

0 个答案:

没有答案