shinyFiles icon indicating copy to clipboard operation
shinyFiles copied to clipboard

shinyDirChoose compatibility problem with shiny.i18n

Open bertolami opened this issue 5 years ago • 6 comments

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.

bertolami avatar Nov 16 '20 11:11 bertolami

I'm not familiar with shiny.i18n. Where are you seeing the as.character(label) code exactly?

vnijs avatar Nov 18 '20 07:11 vnijs

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))))
}

bertolami avatar Nov 18 '20 10:11 bertolami

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.

vnijs avatar Nov 18 '20 19:11 vnijs

A minimal reproducible example would be really useful here. Thanks

vnijs avatar Nov 23 '20 22:11 vnijs

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")"
    )
)

bertolami avatar Nov 24 '20 07:11 bertolami

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
> 

vnijs avatar Nov 28 '20 21:11 vnijs