gpt4 book ai didi

r - 将滚动条添加到 Shiny 的框中

转载 作者:行者123 更新时间:2023-12-04 12:46:41 24 4
gpt4 key购买 nike

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

box( title = "Btest", status = "primary",height = 355, solidHeader = T, 
tableOutput("table1"))

最佳答案

你可以使用 library(DT)。它为 JavaScript 库 DataTables 提供了一个 R 接口(interface)。 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'))
)

在 server.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 information

关于r - 将滚动条添加到 Shiny 的框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45498557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com