[Bug]: Issue calling update_lang() - order of function arguments
Closed this issue · 2 comments
Guidelines
- I agree to follow this project's Contributing Guidelines.
Project Version
0.3.0
Platform and OS Version
macOS 12.6, Windows10 Pro
Existing Issues
No response
What happened?
My shiny apps broke as result of upgrade in shiny.i18n package from v0.2.0 to 0.3.0. The problem occurs in my server.R
includes an observeEvent for language change which includes a call to this package's update_lang() method. At appears the order of arguments to the function changed between versions 0.2.0 and 0.3.0
the call: update_lang(session, input$lang_pick) # works in v 0.2.0 but breaks in 0.3.0
the call: update_lang(input$lang_pick, session) # works in v 0.3.0 but breaks in 0.2.0
The problem also occurs in your minimal tutorial at:
https://appsilon.github.io/shiny.i18n/articles/basics.html
Steps to reproduce
- at your tutorials https://appsilon.github.io/shiny.i18n/articles/basics.html
- with shiny.i18n v0.3.0 package installed
- select code from section "Live Language Change" "Option b" and paste in an App.R file
- create a json translator file. I used the one from the tutorial. In same foldeer as App.R
- ** from your tutorial you must change tag "Hello Shiny!" to "Hello" to be same as in the call i18n$t call in App.R
- note the call to run the App - it crashes when hit the "Go" button
- reverse the arguments in the server function's "update_lang()" call from: update_lang(session, "pl") to update_lang("pl",session)
- rerun the application. It should now work properly.
...
Expected behavior
Updating the package should not break functionality. Order of arguments or the tutorials and the README notes should be corrected or state the naturre of the breaking change.
Attachments
library(shiny)
library(shiny.i18n)
i18n <- Translator$new(translation_json_path = "translation.json")
i18n$set_translation_language("en")
ui <- fluidPage(usei18n(i18n),
p(i18n$t("Hello")),
actionButton("go", "GO!")
)
server <- function(input, output, session) {
observeEvent(input$go,{
#update_lang(session, "pl") # tutorial and 0.2.0 code, breaks with 0.3.0
update_lang("pl",session) # works with v 0.3.0, breaks on 0.2.0
})
}
shinyApp(ui, server)
Screenshots or Videos
No response
Additional Information
No response
Better workaround.
Using named arguments in the function call (instead of positional args) as shown below appears to work in either shiny.i18n package version:
update_lang( language = "pl", session = session )
Hi @rschramm9
Thank you for pointing this out. The tutorial has been already updated. Regarding the change in arguments order - shiny.i18n
is still before its stable 1.0.0 version, so the API of the package can change.
The current version of update_lang
function follows the general approach with session
argument with the given default - so now you should be able to simply use update_lang( language = "pl")
(or update_lang( "pl")
).