Looking for some advice on best way to format table with columns of mixed types, so some are integer, other percentages (with % displayed), others decimal points.
Is there a nice way to edit individual cells. Have tried with htmlwidgets version of DT and formattable?
library(data.table)
library(dplyr)
#Data
names <- c("whole-number1","whole-number2","percentage","decimal-1place","decimal-2place")
group1 <- c(101.000,656.000,0.323,0.69,0.88)
group2 <- c(103.000,635.000,0.453,0.67,0.99)
output_table <- data.table(cbind(names,group1,group2))
#html output table
library(formattable)
formattable(output_table,
list(
group1=formatter(
"span",
style = x ~ ifelse(names == "percentage",
percent(x,digits=1), NA)))
#html output table
library(DT)
datatable(output_table) %>%
formatPercentage("group1",digits=1)