我正在尝试
但是我的数据表自动居中于mainPanel,其标题和内容也未对齐。
示例:
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Test Example"),
mainPanel(
width = 10,
dataTableOutput("cars.table")
)
)
server <- function(input, output) {
output$cars.table <- renderDataTable({
t(cars[1:10, ]) %>%
datatable(class = "compact small",
options = list(columnDefs = list(list(width = "25px", targets = "_all")), scrollX = TRUE, autoWidth = TRUE,
paging = FALSE, ordering = FALSE, searching = FALSE))
})
}
shinyApp(ui = ui, server = server)
更新2019/05/03:
我相信this question指出此问题是由autoWidth = TRUE
引起的,但是在此问题下没有解决方案,并且如果我们要调整列宽,则无法删除{{1} }。
答案 0 :(得分:0)
要对齐,可以使用className = dt-left
。
我猜参数'fillContainer = T'可以完成滚动工作。
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Test Example"),
mainPanel(
width = 10,
dataTableOutput("cars.table")
)
)
server <- function(input, output) {
output$cars.table <- renderDataTable({
t(cars[1:10, ]) %>%
datatable(class = "compact small", fillContainer = T,
options = list(columnDefs = list(list(className = 'dt-left', width = "25px", targets = "_all")), scrollX = TRUE,
paging = FALSE, ordering = FALSE, searching = FALSE))
})
}
shinyApp(ui = ui, server = server)