在启用ScrollX的情况下向右滚动时,我只是试图将最左边的列固定,而无法使其正常工作。知道我需要做些什么吗?
library(shiny)
library(DT)
ui <- fluidPage(
fluidRow(mainPanel(DT::dataTableOutput('mtcars'), width = 12))
)
server <- server <- function(input, output, session) {
output$mtcars <- DT::renderDataTable({
mtcars %>%
DT::datatable(
selection = 'none', rownames = '', filter = 'none',
options = list(
paging = TRUE, searching = TRUE, info = FALSE,
sort = TRUE, scrollX = TRUE, fixedColumns = list(leftColumns = 1)
)
)
})
}
shinyApp(ui = ui, server = server)
此处的版本信息:
> packageVersion('DT')
[1] ‘0.4.16’
> packageVersion('shiny')
[1] ‘1.1.0’
> version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 3.1
year 2016
month 06
day 21
svn rev 70800
language R
version.string R version 3.3.1 (2016-06-21)
nickname Bug in Your Hair
答案 0 :(得分:5)
两个问题:
您需要扩展名FixedColumns
;
第一列实际上是leftColumns = 2
,而不是leftColumns = 1
(我想是行名)。
mtcars %>%
DT::datatable(
selection = 'none', rownames = '', filter = 'none',
extensions = "FixedColumns",
options = list(
paging = TRUE, searching = TRUE, info = FALSE,
sort = TRUE, scrollX = TRUE, fixedColumns = list(leftColumns = 2)
)
)