0

In reactable, you can make edits to named columns as follows:

    columns = list(
        Species = colDef(minWidth = 140),
        AnotherNamedColumn = colDef(align = "center")
)

The data I am using changes weekly, and so I can't use a named column. I need to subset from a df this:

    columns = list(
        df[1,2] = colDef(minWidth = 140),
        df[1,3] = colDef(align = "center")
)

But reactable doesn't like this. Does anyone know how I can get this to work and actually get reactable to evaluate the subset code so I can 'point' to the correct column without naming it?

stefan
  • 90,330
  • 6
  • 25
  • 51
adajam
  • 193
  • 1
  • 10
  • Please make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). And your question/code should include every non-standard package you used, in this case `library(reactable)`. – Martin Gal Sep 01 '21 at 16:43

1 Answers1

1

If I got you right then one option to achieve your desired result would look like so:

  1. Put your colDefs in a list
  2. Set the names of the list according to column positions in your df
  3. Pass the named list to the columns argument
library(reactable)

df <- iris
columns <- list(colDef(minWidth = 140), colDef(align = "center"))
columns <- setNames(columns, names(df)[2:3])
reactable(df, columns = columns)

stefan
  • 90,330
  • 6
  • 25
  • 51