我有一个使用DT-package 显示数据表的闪亮应用程序.我想要的是能够以自定义方式格式化列.例如,我想要一个货币值显示如下:1,234.50€而不是-way DT,它显示它像$ 1,234.5(注意符号的变化,货币符号的位置以及小数点后的数字-点).
MWE看起来像这样:
library(shiny)
library(DT)
shinyApp(
# UI
ui = fluidPage(DT::dataTableOutput('tbl')),
# SERVER
server = function(input, output) {
dat <- data.frame(cur = 1234.5, # supposed to be displayed as: 1,234.50€ | Bad!
# displayed as $1,234.5
perc = 0.123456, # 12.34% | Good!
num = 1000) # 1,000 | Bad! displayed as 1000
# render DT
output$tbl = DT::renderDataTable(
datatable(dat) %>%
formatCurrency(c('cur'), "$") %>%
formatPercentage('perc', 2) %>%
formatRound('num', digits = 0)
)
}
)
Run Code Online (Sandbox Code Playgroud)
但它做得相当不错,当将货币符号更改为时€,符号消失.当插入另一个字符如"E"时,字符仍然显示在开头而不是结尾.此外,数值不会得到"大标记".
有任何想法吗?
您可以更改数据表包中 .js 文件中货币符号的位置。
\n\n编辑 DTWidget.formatCurrency 函数的行
\n\n $(thiz.api().cell(row, col).node()).html(currency + markInterval(d, interval, mark));\nRun Code Online (Sandbox Code Playgroud)\n\n简单地
\n\n $(thiz.api().cell(row, col).node()).html(markInterval(d, interval, mark) + currency);\nRun Code Online (Sandbox Code Playgroud)\n\n在 R 库目录中的 DT/htmlwidgets/datatables.js 文件中。
\n\n至于 \xe2\x82\xac 符号,
\n\nformatCurrency(c(\'cur\'), currency = "\\U20AC", interval = 3, mark = ",", digits = 2)\nRun Code Online (Sandbox Code Playgroud)\n\n对我有用,这就是你尝试过的,但你没有看到任何符号?
\n| 归档时间: |
|
| 查看次数: |
7524 次 |
| 最近记录: |