So I have a situation where I would like to use an object in a tag$button()
. This is to work around the fact that the columns may change.
It works on the first click and then stops working and the whole table disappears on subsequent clicks.
library(htmltools)
data <- MASS::Cars93[1:5, c("Manufacturer", "Model", "Type", "Price",
"Passengers", "DriveTrain", "Cylinders", "EngineSize")]
hidden_cols <- c('Passengers', 'DriveTrain', 'Cylinders', 'EngineSize')
htmltools::browsable(
tagList(
tags$button(
"Show/hide more columns",
onclick = "Reactable.setHiddenColumns('cars-vis-table', prevColumns => {
return prevColumns.length === 0 ? [hidden_cols] : []
})"
),
reactable(
data,
columns = list(
Passengers = colDef(show = FALSE),
DriveTrain = colDef(show = FALSE),
Cylinders = colDef(show = FALSE),
EngineSize = colDef(show = FALSE)
),
elementId = "cars-vis-table"
)
)
)