volfi
volfi

Reputation: 477

R Reactable hide columns by default

I would like to display a dataframe consisting on many columns in a reactable. Since only very few columns are interesting the default setting should be to hide the columns. When I do this it is however impossible to see any columns since none are displayed at all. What is the correct way to do this?

library(reactable)
reactable(mtcars,
          defaultColDef = colDef(show = F),
          columns = list(
            mpg = colDef(show =T)
          ))

In this case no columns are displayed despite mpg being set to TRUE.

Upvotes: 1

Views: 3174

Answers (2)

GGAnderson
GGAnderson

Reputation: 2210

It seems what you want to do is use defaultColDef to "hide" all columns NOT explicitly assigned for display. This can be done by assigning defaultColDef last:

library(reactable)
reactable(mtcars,
      columns = list(
        mpg = colDef(show =T)),
      defaultColDef = colDef(show = F)
      )

Upvotes: 1

Della
Della

Reputation: 71

If you only want to display mpg column, you can simply subset this column in reactable:

reactable(mtcars[0:1],
          defaultColDef = colDef(show = T))

Upvotes: 3

Related Questions