Closed bjcarothers closed 5 months ago
While we might want to somehow fix this on shinyapps, there is a fix that's available now (and is also more reliable than relying system locales): use a date-time package that has different locales built in. For example, here's an example using the clock package:
library(clock)
date <- as.Date("2023-01-02")
date_format(date, format = "%d %B %Y", locale = clock_locale("en"))
#> [1] "02 January 2023"
date_format(date, format = "%d %B %Y", locale = clock_locale("es"))
#> [1] "02 enero 2023"
date_format(date, format = "%d %B %Y", locale = clock_locale("pt"))
#> [1] "02 janeiro 2023"
Created on 2024-01-16 with reprex v2.0.2.9000
(I don't know if the country specifiers are important for your use case, although a little research suggests that at least Spain and Latin America use the same month names, you can also use clock_labels()
to provide your own names.)
Yep, that did it. We don't need the country specifiers yet, but good to know about clock_labels() if we need it in the future. Thanks!
I've built an app where users have the option to generate reports in English, Spanish, and Portuguese. The reports have a time stamp at the top that relies on
Sys.setlocale
andformat
to translate and display the date properly depending on the selected language. (E.g. "02 março, 2023" for Portuguese.) Works locally, but not when deployed.Stripped down app.R:
Following the advice here about making non-local locales available in rsconnect before deploying, I've tried running a few things in the console to deploy the app:
Attempt 1:
Attempt 2:
Attempt 3:
In each case, only the Spanish locale (last one specified) works, and I get the following errors in the log:
Is it possible to make all three available in shinyapps.io?
(Apologies for earlier crospostings here and here, but it didn't get any takers.)