0

Hope you are doing great today.

I have an issue trying to make some columns sticky. Here is a piece of code that highlights the error I get: Error in colDef: unused argument (sticky = "left")

Not sure what I am doing wrong, or if there is an issue with aggregation and sticky columns.

Using:

  • reactable 0.3,
  • $platform [1]: "x86_64-apple-darwin17.0",
  • $version.string: "R version 4.2.0 (2022-04-22)".

Reproducible example:

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)

HK6
  • 1

1 Answers1

0

I've encountered the same problem, and the solution for me was to include the "sticky" option inside the styling, as described here: 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))
Iria Roca
  • 161
  • 5