Appsilon / shiny.i18n

Shiny applications internationalization made easy
https://appsilon.github.io/shiny.i18n/
Other
169 stars 38 forks source link

Issues : "Error in multmerge" - HELP #67

Closed Sebastianmarzini closed 2 years ago

Sebastianmarzini commented 3 years ago

Good morning, I am quite new in using R and R shiny. I am trying to create an app and to give the possibility to change the language using the shiny.i18n package. I have created a csv file as mentioned in the vignette, with 2 columns (1 for english and 1 for italian) but as I run the script it gives me this error: Warning in load_local_config(translation_csv_config) : You didn't specify config translation yaml file. Default settings are used. Error in multmerge(all_files, sep) : Key translation is not the same in all files.

Here i post all the code:

rm(list=ls())

library(ecmwfr)
library(keyring)
library(shiny)
library(shinyalert)
library(shinyFiles)
library(stringr)
library(ncdf4)
library(devtools)
library(usethis)
library(foreMast)
library(shiny.i18n)

tr <- Translator$new(translation_csvs_path = "C/Users/Seba/Progetti_gitLab/aforclimate/C4/test_pasciona/www/")
tr$set_translation_language("en")

ui <- fluidPage(
  shiny.i18n::usei18n(tr),
  div(style = "float: right;", 
      selectInput('selected_language',
                  tr$t("Change language"),
                  choices = tr$get_languages(),
                  selected = tr$get_key_translation())
  ),

  titlePanel(
    h1(strong(tr$t("Forecast of seed production of "), em("Fagus sylvatica L."), tr$t(" in the current year")), align = "center")
  ),
  sidebarLayout(
    sidebarPanel(
      fluidRow(
        style = "background-color:#ccffcc;",
        style = "border: 2px black;",
        h2(strong(tr$t("Climatic data download"))),
        h3(tr$t("1-Registration to the Copernicus CDS service and login")),
        p(tr$t("To access to the service it is necessary to register at the following "), 
          a(tr$t("site"), href = "https://cds.climate.copernicus.eu/user/register?destination=%2Fcdsapp%23!%2Fhome"),
          tr$t(" and login")),
        h3(tr$t("2-Creation of the query")),
        p(tr$t("To obtain the file, it is necessary to go on the download  "), 
        a(tr$t("page"), href = "https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-land-monthly-means?tab=form"), 
        tr$t("of the ERA 5 dataset and select the following parameters: ")),
        h4("a) ", strong("Product type")),
        p("'Monthly averaged reanalysis'", style = "color:red"),
        h4("b) ", strong("Variable")),
        p(strong("Temperature: ")), p("'2m temperature'", style = "color:red"),
        p(strong("Wind, Pressure and Precipitation: ")), p("'Total precipitation'", style = "color:red"),
        h4("c) ", strong("Year")), p(tr$t("Select all the available years"), style = "color:red"),
        h4("d) ", strong("Month")), p(tr$t("Select all the available months"), style = "color:red"),
        h4("e) ", strong("Time")), p(tr$t("Select the only available time ('00:00')"), style = "color:red"),
        h4("f) ", strong("Geograpichal area")),
        p("'Sub-region extraction'", style = "color:red"), p(tr$t("Insert the coordinates (lat, lon) of the interested location in the specific spaces. "),
        strong(tr$t("IMPORTANT")),tr$t(": insert two decimal digits, with the first one being the same as that of the opposite direction (eg. North: 43.87, East: 12.02, South: 43.86, West: 12.01) using the minus sign for sites under the equator and west to the meridian ‘0’")),
        h4("g) ", strong("Format")), p("'NetCDF (experimental)'", style = "color:red"), 
        h4(tr$t("Click on "), strong("Submit Form")),
        h3(tr$t("3-Data download")),
        p(tr$t("Once the form has been sent, you will be redirected on the "), 
          a(tr$t("page"), href = "https://cds.climate.copernicus.eu/cdsapp#!/yourrequests?tab=form"),
          tr$t(" where the product will be available clicking on the "), strong("'Download'"), 
          tr$t(" button, as soon as the queue time has been accomplished ('Status = Queued)'")),
      ),
      fluidRow(br()),
      fluidRow(
        style = "background-color:#ccffee;",
        style = "border: 2px black;",
        h2(strong(tr$t("Climatic data upload and seed production calculation"))),
        p(tr$t("Upload the "), strong(".nc"), tr$t("file and click on "), strong(tr$t("Chart")), 
          tr$t("to generate the probability chart")),
        fileInput("upfile", tr$t("Choose a file .nc"),
                  multiple = FALSE,
                  accept = c(".nc")),
        actionButton("submit", label = strong(tr$t("Chart")), 
                     style="color: white; background-color: #3385ff; position: relative; left: 41%")
      )
    ),
    mainPanel(
      plotOutput("plot")
    )
    )
  )

server <- function(input, output, session) {

  observeEvent(input$selected_language, {
    # This print is just for demonstration
    print(paste("Language change!", input$selected_language))
    # Here is where we update language in session
    shiny.i18n::update_lang(session, input$selected_language)
  })

  # upload del file .nc
  observeEvent(input$submit, {
    file <- input$upfile
    filename <- gsub("\\\\", "/", file$datapath)
    output$plot<- renderPlot({
      probPlot(mastFaSyl(fName = filename,  weighting = "standard"))
      })
    })
  }

# Run the app
shinyApp(ui, server)

I really hope that someone could give me a hint about to solve this issue. Thanks in advance!!

jakubsob commented 3 years ago

Hello @Sebastianmarzini, this error happens when your translation csv files don't have the same "base" translation language.

This error occurs when you have for example two such csv files in your translation_csvs_path:

translation_it.csv

en,it
Hello,Ciao

translation_es.csv

e,es
Hello,Hola

First column of all translation files should have the same name, if our "base" translation language is English, then first column in both files should be en. Error is thrown due to translation_es.csv having first column named e.

Do you have any other csv files in your C/Users/Seba/Progetti_gitLab/aforclimate/C4/test_pasciona/www/ folder? The issue in your case may be coming from that the function that reads translation csvs actually reads all csvs in the directory, see this function. This is confusing as vignette says that the file needs to have translation_ prefix. This needs to be fixed on our side. At the moment I'd like to suggest you use a separate folder for storing translations (C/Users/Seba/Progetti_gitLab/aforclimate/C4/test_pasciona/www/translations) to make sure only those files are read by Translator.

I hope this helps you solve your issue. In case you have any other questions feel free to reach out. Cheers