无法使用可反应在 R 闪亮应用中制作粘性列

  • 本文关键字:应用 r shiny reactable
  • 更新时间 :
  • 英文 :


祝你今天一切顺利。

我有一个问题,试图使一些列粘。下面是一段代码,突出显示了我得到的错误:colDef: unused argument (sticky = "left")

不确定我做错了什么,或者是否有聚合和粘性列的问题。

使用:

  • reactable 0.3,
  • $platform [1]: "x86_64-apple-darwin17.0",
  • 美元版本。字符串:"R version 4.2.0 (2022-04-22)"

可再生的例子:

library(shiny)
library(reactable)
library(tidyverse)
ui <- fluidPage(
titlePanel("Test sticky column"),

mainPanel(
reactableOutput("reactTop10")
)
)
server <- function(input, output) {
data<-reactive({
data.frame(Business.Name = c("Shop1","Shop2","Shop1","Shop2"),
Method.Name = c("m1","m1","m2","m2"),
Margin = c(25,32,43,12))
})

output$reactTop10 <- renderReactable({
sticky_style <- list(backgroundColor = "#f7f7f7")
expr = reactable(
data(),
defaultColDef = colDef(
footer = function(values, name) {
htmltools::div(name, style = list(fontWeight = 600))
}
),
rowStyle = JS("function(rowInfo) {
if (rowInfo.aggregated == true) {
return { fontWeight: 'bold' }
}
}"),
groupBy = c("Business.Name",
"Method.Name"),
columns = list(
Business.Name = colDef(style = list(fontWeight = 600),
sticky = "left",
headerStyle = list(borderRight = "1px solid #eee"),
header = with_tooltip("Business.Name", "Names of our top 10 merchants")),
Method.Name = colDef(aggregate = "unique",
header = with_tooltip("Method.Name", 
"Name of the method bla bla")),
Margin = colDef(aggregate = "mean",
header = with_tooltip("Margin", 
"Name of the premium services"))
))
})
}
# Run the application 
shinyApp(ui = ui, server = server)

我也遇到过同样的问题,我的解决方案是加入"黏性";选项,如下所示:https://rdrr.io/github/glin/reactable/f/vignettes/sticky-columns.Rmd

colDef(style = list(position = "sticky", left = 0, background = "#fff", zIndex = 1),
headerStyle = list(position = "sticky", left = 0, background = "#fff", zIndex = 1))

最新更新