R可渲染-冻结列

R可渲染-冻结列,r,dataframe,shiny,datatable,conditional-formatting,R,Dataframe,Shiny,Datatable,Conditional Formatting,正在寻找向R中的可渲染文件添加冻结帧的帮助。我使用的是renderTable而不是DTpackagerenderDataTable,因为我有一个超过400列的数据帧DT被渲染阻塞,但是renderable似乎工作得很快 以下是一个例子: if (interactive()) { library(DT) fruit <- c("Apple", "Orange", "Pear", "Banana")

正在寻找向R中的
可渲染文件添加冻结帧的帮助。我使用的是
renderTable
而不是
DT
package
renderDataTable
,因为我有一个超过400列的数据帧
DT
被渲染阻塞,但是
renderable
似乎工作得很快

以下是一个例子:

if (interactive()) {
  library(DT)
  
  fruit <- c("Apple", "Orange", "Pear", "Banana")
  num <- c(54, 25, 51, 32)
  Oct2020 <- c(10, 15, 20, 25)
  Nov2020 <- c(5, 7, 10, 15)
  Dec2020 <- c(7, 9, 12, 17)
  Jan2021 <- c(6, 9, 2, 0)
  Feb2021 <- c(15, 30, 12, 2)
  Mar2021 <- c(6, 7, 8, 10)
  
  data <- data.frame(fruit, num, Oct2020, Nov2020, Dec2020, Jan2021, Feb2021, Mar2021)
  
  ui <- fluidPage(
    fluidRow(
      column(width = 1, numericInput("numFruit", "Number of Fruit", value = 10)),
      column(width = 1, div(style = "margin-top: 25px", actionButton("btnUpdate", "Update")))
    ),
    
    fluidRow(
      div(style = 'height: 200px; width: 500px; overflow: scroll; font-size: 90%', align = "left", tableOutput("dt_Fruit"))  
    )
  )
  
  server <- function(input, output, session) {
    output$dt_Fruit <- renderTable(data, striped = TRUE, hover = TRUE, bordered = TRUE)
  }
  shinyApp(ui, server)
}
if(交互式()){
图书馆(DT)

水果你的两个问题非常不同。我回答第二个问题。请为第一个问题打开另一个问题

我提出的解决方案使用了jQuery插件冻结表

library(shiny)

widetbl <- t(iris[1:40,]) # a wide table for the illustration

js <- HTML(paste0(c(
  '$(document).on("shiny:value", function(evt) {',
  '  if(evt.name === "wideTable") {',
  '    setTimeout(function() {',
  '      $("#wideTable").freezeTable({',
  '        fastMode: true,',
  '       columnNum: 2',
  '      });',
  '    }, 0);',
  '  }',
  '});'
), collapse = "\n"))

ui <- fluidPage(
  tags$head(
    tags$script(
      src = "https://cdn.jsdelivr.net/gh/yidas/jquery-freeze-table/dist/js/freeze-table.min.js"
    ),
    tags$script(js)
  ),
  br(),
  tableOutput("wideTable")
)

server <- function(input, output, session){
  
  output[["wideTable"]] <- renderTable({
    widetbl
  })
  
}

shinyApp(ui, server)
库(闪亮)
宽带