jrowen / rhandsontable

A htmlwidgets implementation of Handsontable.js
http://jrowen.github.io/rhandsontable/
Other
380 stars 147 forks source link

How to register new language with numbro and use with rhandsontable? #404

Open rcst opened 2 years ago

rcst commented 2 years ago

Hi,

great package! I'm building a data entry shiny app for an Albanian client. I'd like to format certain columns as Albanian currency.

The shiny app is a R package. I put a file into inst/assets/js/numbro-al.js with the following content:

numbro.registerLanguage({
    languageTag: "al-AL",
    languageName: "Albanian (Albania)",
    delimiters: {
        thousands: ",",
        decimal: "."
    },
    abbreviations: {
        thousand: "k",
        million: "m",
        billion: "b",
        trillion: "t"
    },
    ordinal: (number) => {
        return number === 1 ? "st" : "th";
    },
    currency: {
        symbol: "L",
        position: "postfix",
        code: "ALL"
    },
    currencyFormat: {
        thousandSeparated: true,
        totalLength: 3,
        spaceSeparated: true,
        average: true
    },
    formats: {
        fourDigits: {
            totalLength: 4,
            spaceSeparated: true,
            average: true
        },
        fullWithTwoDecimals: {
            output: "currency",
            mantissa: 2,
            spaceSeparated: true,
            thousandSeparated: true
        },
        fullWithTwoDecimalsNoCurrency: {
            mantissa: 2,
            thousandSeparated: true
        },
        fullWithNoDecimals: {
            output: "currency",
            spaceSeparated: true,
            thousandSeparated: true,
            mantissa: 0
        }
    }
});

I'm adding this script via htmltools::htmlDependency()

(in R/utils.R)

myDependencies <- function() {
    htmltools::htmlDependency(name = "evidenca-portal-assets", version = "0.1",
                  package = "evidenca.portal",
                  src = "assets",
                  script = "js/numbro-al.js")
}

eventually here (R/ui.R)

shiny_ui <- function() {
...
myDepdencies(),
...
}

In R/server.R I declare it like hot_cols(..., cols = ..., format = "0,000.00 $", language = "al-AL")

However numbers are displayed like $ 10,000.00 and I get Uncaught ReferenceError: numbro is not defined at numbro-al.js:1:1 in my browsers console. I don't know JavaScript unfortunately.

Any hint?