如何使水平滚动条在 DT::datatable 中可见 [英] How to make the horizontal scrollbar visible in DT::datatable

查看:28
本文介绍了如何使水平滚动条在 DT::datatable 中可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 R 闪亮 &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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆