![](/img/trans.png)
[英]Make DT (DataTable) responsive using flexdashboard with Shiny in R
[英]R Shiny DT responsive datatable height
我正在嘗試在Shiny中使用全高數據表,該表根據可用高度顯示許多行,並且頁面數也會發生變化。
DT
responsive
擴展適用於寬度。 身高是否可以相等?
答案可能是使用javascript修改show N entries
頂部show N entries
的框,使其具有新的N
值,並根據已知行的大小對表可占用的最大空間進行一些計算。
這是一個開始:
library(shiny)
ui <- fluidPage(
titlePanel("Arbitrary component to remove space in the page"),
dataTableOutput('table_name')
)
server <- function(input, output) {
output$table_name <- DT::renderDataTable({
data.frame(a=1:100, b = 100:1, c = 101:200)
})
}
shinyApp(ui = ui, server = server)
任何幫助將不勝感激
下面是一個基本示例,說明如何根據窗口的高度更改表中的行數。 這不是最有效的方法,但是可以並且可以幫助您創建更好的解決方案。
請注意,調整工作台的延遲應根據您的需要進行調整。
jscode.autoHeightDT <- '
autoHeightDT = function() {
var offset = 100; // pixels used for other elements like title, buttons, etc
// compute the number of rows to show in window
var n = Math.floor(($(window).height() - offset) / $("#table_name tr").height());
// set the new number of rows in table
t = $("#table_name .dataTable").DataTable().page.len(n).draw();
}
// to adjust the height when the app starts, it will wait 0.8 seconds
setTimeout(autoHeightDT, 800);
// to react to changes in height of window
$(window).resize(function() {
autoHeightDT();
});
'
library(shiny)
library(DT)
ui <- fluidPage(
tags$script(jscode.autoHeightDT), # includes JavaScript code
titlePanel("Arbitrary component to remove space in the page"),
dataTableOutput('table_name')
)
server <- function(input, output) {
output$table_name <- DT::renderDataTable({
data.frame(a=1:100, b = 100:1, c = 101:200)
})
}
shinyApp(ui = ui, server = server)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.