shinyDirChoose compatibility problem with shiny.i18n
If a translationText is used as label of a shinyDirChoose the entire span code is displayed in the button.
The problem seems to be the as.character(label). If the as.character is removed to translation is displayed correctly.
I'm not familiar with shiny.i18n. Where are you seeing the as.character(label) code exactly?
In the shinyDirButton function. just at the end where data-val is set:
> shinyDirButton
function (id, label, title, buttonType = "default", class = NULL,
icon = NULL, style = NULL)
{
value <- restoreInput(id = id, default = NULL)
tagList(singleton(tags$head(tags$script(src = "sF/shinyFiles.js"),
tags$link(rel = "stylesheet", type = "text/css",
href = "sF/styles.css"), tags$link(rel = "stylesheet",
type = "text/css", href = "sF/fileIcons.css"))),
tags$button(id = id, type = "button", class = paste(c("shinyDirectories btn",
paste0("btn-", buttonType), class, "action-button"),
collapse = " "), style = style, `data-title` = title,
`data-val` = value, list(icon, as.character(label))))
}
Thanks! What "type" is your label when you pass it to shinyDirButton? If it is of type character then I could add a check and only convert if not a character.
A minimal reproducible example would be really useful here. Thanks
library(shiny)
library(shinyFiles)
library(shinyjs)
library(shiny.i18n)
i18n <- Translator$new(translation_csvs_path = "data/i18n")
ui <- fluidPage(
shinyjs::useShinyjs(),
shiny.i18n::usei18n(i18n),
shinyDirButton(
'buttonId',
label = i18n$t("MyLabel"),
title = "i18n$t("MyTitle")"
)
)
I get the output below when running this example. Is there anything else I need to check this?
> library(shiny)
> library(shinyFiles)
> library(shinyjs)
Love shinyjs? Consider donating:
https://github.com/sponsors/daattali
Attaching package: ‘shinyjs’
The following object is masked from ‘package:shiny’:
runExample
The following objects are masked from ‘package:methods’:
removeClass, show
> library(shiny.i18n)
>
> i18n <- Translator$new(translation_csvs_path = "data/i18n")
Error in multmerge(all_files, sep) :
Key translation is not the same in all files.
In addition: Warning message:
In load_local_config(translation_csv_config) :
You didn't specify config translation yaml file. Default settings are used.
> ui <- fluidPage(
+ shinyjs::useShinyjs(),
+ shiny.i18n::usei18n(i18n),
+ shinyDirButton(
+ 'buttonId',
+ label = i18n$t("MyLabel"),
+ title = "i18n$t(\"MyTitle\")"
+ )
+ )
Error in shiny.i18n::usei18n(i18n) : object 'i18n' not found
>