I would like to have the grouped columns bold. But the function bold
doesnt accept a string type of column name. How can I make input[[paste0("options_agg_", input$tabs)]]
work for selecting rows in bold function?
This works:
ft <- as_grouped_data(filtered_other(), groups = input[[paste0("options_agg_", input$tabs)]], columns = input[[paste0("options_dim_", input$tabs)]]) %>%
as_flextable() %>%
bold(i = ~ !is.na(Product.category))
htmltools_value(ft)
and this does not:
ft <- as_grouped_data(filtered_other(), groups = input[[paste0("options_agg_", input$tabs)]], columns = input[[paste0("options_dim_", input$tabs)]]) %>%
as_flextable() %>%
bold(i = ~ !is.na(input[[paste0("options_agg_", input$tabs)]]))
htmltools_value(ft)
I don't want it to be always set to Product.category
.
I have tried: as.formula
. I have also considered eval & parse. But I did not make it work
One option would be to use reformulate
to create your formula object.
Using a minimal reproducible example based on mtcars
:
library(flextable)
library(magrittr)
col <- "mpg"
fml <- reformulate(paste0("!is.na(", col, ")"))
fml
#> ~!is.na(mpg)
ft <- as_grouped_data(mtcars, groups = "cyl", columns = c("cyl", "mpg")) %>%
as_flextable() %>%
bold(i = fml)
ft