在我闪亮的包中,我有以下代码:
output$growthTable <- renderTable({
table <- makeTable()
colnames(table) <- c("Year","BOY Balance", "Yearly Growth", "EOY Contribution", "EOY Balance")
return(table)
}, include.rownames = FALSE)
Run Code Online (Sandbox Code Playgroud)
如何使最后 4 列中有逗号。所以例如10000变成10,000?
由于您没有提供可重现的示例,因此这里提供了如何操作的有效演示。据我所知,没有办法在renderTable语句中指定数字格式,因此您必须重新格式化您的值。关键是使用format或prettyNum与big.mark选项集。但是,请注意,这会将您的数值转换为字符。建议您在不对值进行进一步处理后执行此格式转换。
require(shiny)
data(iris)
runApp(
list(
ui = fluidPage(
headerPanel('Print big numbers with comma'),
mainPanel(
tableOutput("table"))
),
server = function(input, output) {
makeTable <- reactive({
iris[,1:4] <- iris[1:4] * 1000
#iris[,1:4] <- sapply(iris[,1:4], FUN=function(x) format(x, big.mark=","))
iris[,1:4] <- sapply(iris[,1:4], FUN=function(x) prettyNum(x, big.mark=","))
iris
})
output$table <- renderTable({
table <- makeTable()
table
}, include.rownames = FALSE)
}
)
)
Run Code Online (Sandbox Code Playgroud)