Search code examples
rreactable

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.


Solution

  • 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)
          )