DT in Shiny and R: Custom number formatting

前端 未结 1 1903
半阙折子戏
半阙折子戏 2021-02-14 19:46

I have a shiny-app that displays a datatable using the DT-package. What I want is to be able to format columns in a custom way. For example I want a currency value

1条回答
  •  余生分开走
    2021-02-14 19:54

    You can change the position of the currency symbol in the .js file from the datatable package.

    Edit the line of the DTWidget.formatCurrency function

     $(thiz.api().cell(row, col).node()).html(currency + markInterval(d, interval, mark));
    

    to simply

     $(thiz.api().cell(row, col).node()).html(markInterval(d, interval, mark) + currency);
    

    in the DT/htmlwidgets/datatables.js file in the directory of your R librarys.

    As for the € Symbol,

    formatCurrency(c('cur'), currency = "\U20AC", interval = 3, mark = ",", digits = 2)
    

    does work for me, thats what you tried and you don't see any symbol?

    0 讨论(0)
提交回复
热议问题