如何使水平滚动条在DT :: datatable中可见 [英] How to make the horizontal scrollbar visible in DT::datatable
问题描述
使用R Shiny& DT包,我正在创建某些表.列数随每个用户输入&不固定的.我提供了以下代码片段,其中包括一个水平滚动条,以便在列数很大时,用户可以滚动浏览不直接可见的列.
Using R shiny & DT package, I am creating certain tables. The number of columns vary as per user input & is not fixed. I have included the following code snippet to include a horizontal scrollbar so that when the number of columns is large, the user can scroll through the columns that are not directly visible.
server.R:
output$results <- DT::renderDataTable({
DT::datatable(data = datasetInput(),
options = list(scrollX = TRUE,...)
)
})
<code reduced for brevity>
使用上面的代码,水平"滚动条最初不可见,但是当我单击一行并按键盘上的向右箭头时出现.不管我有多少列,一旦启动表,滚动条是否有任何可见的方式?我可以使用鼠标指针拖动滚动条吗?
Using the above code, the Horizontal scrollbar is not visible at first but appears when I click on a row and hit right arrow on my keyboard. Is there any way the scroll bar becomes visible as soon as the table is fired up, no matter how many columns I have, and I can drag the scrollbar using the mouse pointer?
更新:
我尝试了以下答案中的代码,这就是我看到的-没有水平滚动条.
I tried the code in the answer below and this is what I see - no horizontal scrollbar.
推荐答案
如果您不需要滚动条,我认为您不能(或应该)轻松地强制滚动条,但是上面的代码对我来说很好用,页面初始化时显示滚动条.也许问题出在数据或其他方面.
I don't think you can (or should) force a scrollbar easily if you don't need one, but the above code works fine for me, it shows a scrollbar when the page initializes. Maybe the problem is with the data or something else.
这是一个最小的示例,页面加载时具有水平滚动条
Here's a minimal example that has a horizontal scrollbar on page load
runApp(shinyApp(
ui = fluidPage(
DT::dataTableOutput("results", width = 300)
),
server = function(input, output, session) {
output$results <- DT::renderDataTable(
mtcars,
options = list(scrollX = TRUE)
)
}
))
这篇关于如何使水平滚动条在DT :: datatable中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!