在闪亮的框中添加滚动条

问题描述 投票:0回答:2

我使用 box() 函数在 R 闪亮的仪表板页面上实现了一个框,它加载表格并表示一列充满人口数的列。然而,数字超出了表格,看起来非常糟糕。我希望在框中添加一个滚动条,以便数据保留在框中,并且我可以轻松向下滚动。

box( title = "Btest", status = "primary",height = 355, solidHeader = T, 
                              tableOutput("table1"))
r shinydashboard r-box
2个回答
7
投票

您可以使用库(DT)。它为JavaScript库DataTables提供了R接口。 R 数据对象(矩阵或数据框)可以在 HTML 页面上显示为表格,并且 DataTables 在表格中提供过滤、分页、排序和许多其他功能。

您的代码将如下所示:

ui.r:

box(
title = "View Data", 
width = NULL,
status = "primary", 
solidHeader = TRUE,
collapsible = TRUE,
div(style = 'overflow-x: scroll', DT::dataTableOutput('view_data'))
     )

在服务器.r

view_data_fun<-eventreactive/reactive/observe/observeevent({

#your table generation code

  })

output$view_data<-DT::renderDataTable({
    DT::datatable(view_data_fun(),rownames = FALSE)%>%formatStyle(columns=colnames(view_selected_data_fun()),background = 'white',color='black')
  })

您可以更改%>%formatstyle中的选项。 了解更多请阅读DT信息


4
投票

只需添加 HTML 样式选项就可以了!

 box( title = "Btest", status = "primary",height = 355, solidHeader = T, 
                                  tableOutput("table1"), style = "overflow-x: scroll")
© www.soinside.com 2019 - 2024. All rights reserved.