-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to manage dynamically-appearing columns within the columns list? #65
Comments
JoshADHD
changed the title
How do manage dynamically-appearing columns within the columns list?
How to manage dynamically-appearing columns within the columns list?
Jul 31, 2020
Hi, Is If so, you can programmatically create named lists by combining them with library(reactable)
# Separate named list of colDefs to add. Could be an empty list as well.
extra_columns <- list(
cyl = colDef(name = "CYL"),
disp = colDef(name = "DISP")
)
# Method 1: this won't work due to "`columns` must be a named list of column definitions"
# because extra_columns is added as a nested list
reactable(
mtcars,
columns = list(
mpg = colDef(name = "MPG"),
extra_columns,
hp = colDef(name = "HP")
)
)
# This is equivalent to:
reactable(
mtcars,
columns = list(
mpg = colDef(name = "MPG"),
list(
cyl = colDef(name = "CYL"),
disp = colDef(name = "DISP")
),
hp = colDef(name = "HP")
)
)
#####
# Method 2: this works because c() combines and flattens the named lists
reactable(
mtcars,
columns = c(
list(mpg = colDef(name = "MPG")),
extra_columns,
list(hp = colDef(name = "HP"))
)
)
# This is equivalent to:
reactable(
mtcars,
columns = list(
mpg = colDef(name = "MPG"),
cyl = colDef(name = "CYL"),
disp = colDef(name = "DISP"),
hp = colDef(name = "HP")
)
) |
Thank you, this is exactly the solution I needed! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, I have a table that I pivot_wider to reveal the same statistic, but at different points in time. The number of time-points changes dynamically depending on the statistic. I'd like to be able to manage the list of colDef() calls programatically to handle these "new" columns as they appear. Many of the columns are static, but the time-points in particular can be a single point, or upwards of five/six points.
My attempt at this now is:
Then, in the columns argument of reactable()
This is returning an error that I'm not providing a named list of colDef() functions.
Any insight into how I might tackle this?
The text was updated successfully, but these errors were encountered: