glin / reactable

Interactive data tables for R
https://glin.github.io/reactable
Other
613 stars 79 forks source link

Sticky columns not working when aggregating rows? #247

Open kamalmoona opened 2 years ago

kamalmoona commented 2 years ago

Hi,

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, and:

R.Version()
$platform
[1] "x86_64-apple-darwin17.0"

$arch
[1] "x86_64"

$os
[1] "darwin17.0"

$system
[1] "x86_64, darwin17.0"

$status
[1] ""

$major
[1] "4"

$minor
[1] "2.0"

$year
[1] "2022"

$month
[1] "04"

$day
[1] "22"

$`svn rev`
[1] "82229"

$language
[1] "R"

$version.string
[1] "R version 4.2.0 (2022-04-22)"

$nickname
[1] "Vigorous Calisthenics"

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)
glin commented 2 years ago

Hi, can you double-check that reactable 0.3.0 or later is installed, and packageVersion("reactable") reports 0.3.0 or later? The error message Error in colDef: unused argument (sticky = "left") suggests that an older version without the sticky argument is installed.

kamalmoona commented 1 year ago

Hi,

Yes I seem to have the right version…

On 2 Jul 2022, at 22:21, Greg Lin @.***> wrote:

packageVersion("reactable")