DT-datatable language settings from RMarkdown not recognized in external browsers (Chrome, Firefox)

DT-datatable language settings from RMarkdown not recognized in external browsers (Chrome, Firefox)

rkbauerrkbauer Posts: 5Questions: 0Answers: 0

Hi there,
I am trying to apply German language settings to all the datatables generated within an RMarkdown script. I managed to do this via the following piece of code:

options(DT.options = list(
  language = list(url = '//cdn.datatables.net/plug-ins/1.11.3/i18n/de_de.json')
  ))

In fact the datatables are being correctly exported and all buttons and formatting appears in German in the internal RStudio-browser. However, if I open the generated html file in Chrome or Firefox, the datatables are formatted in English.

I could not find any option to fix this. Please let me know if you know any solution to this, even if it means to include the code in a css file.. Here is the full code example for RMarkdown: (note that you have to change the 2 chunk-quotation marks
to 3 quotation marks to run the example.

---
title: "DT datatable language issue"
output: html_document
---

``{r setup, include=FALSE,echo=FALSE}
knitr::opts_chunk$set(echo = TRUE)
``

``{r load libraries, echo=FALSE, include=FALSE}
library(DT)
library(dplyr)
options(DT.options = list(
  language = list(url = '//cdn.datatables.net/plug-ins/1.11.3/i18n/de_de.json')
  ))
``

## Test Table

``{r pressure, echo=FALSE}
cars %>% datatable()
``

Replies

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • rkbauerrkbauer Posts: 5Questions: 0Answers: 0
    edited November 2021

    Please find below the code of the generated html:
    Link to Test Case

    The generated output appears to be correctly formatted. I have also attached the generated html from RMarkdown to verify the issue in a browser.
    Hope this works out!

  • rkbauerrkbauer Posts: 5Questions: 0Answers: 0

    In order to clarify my last comment:
    If you click on the Link to the test case, the datatable in the "output" tab appears to be correctly formatted in German. However, the html-code is identical to the that of the DT-datatable-language-issue.html, which appears in English when opened in a browser.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    That test case doesn't run, it's giving errors as jQuery isn't included. I'm not seeing any reference to the German URL though in that test case or your HTML file. Could you take a look, please, as you may have posted the wrong version,

    Colin

  • rkbauerrkbauer Posts: 5Questions: 0Answers: 0

    Hmm.. The html-testfile "DT-datatable-language-issue.html" which I posted earlier is correct, but the linked testcase on http://live.datatables.net/ apparently did not save the uploaded html-code..

    I have posted the code now over here:
    https://jsfiddle.net/9t5cbogw/

    I hope this works out now.
    Again, what is weird is that if I upload the code from the html-file on any of these test case plattforms (jsfiddle or live.datatables.net) the datatable in the output tab is correctly formatted in German. However, if I open the underlying html file in a browser the datatable appears in English.

    The link to the German URL is in line 180:

    "language":{"url":"//cdn.datatables.net/plug-ins/1.11.3/i18n/de_de.json"}
    
  • allanallan Posts: 61,663Questions: 1Answers: 10,095 Site admin

    "url":"//

    Is the problem. That is a protocol relative url, so if you are loading your HTML file with file:// then it is going to try and resolve that url as file://cdn.datatables.net... which obviously doesn't exist.

    There should be an error message about that in your browser's console or network panel.

    The fix - use url: 'https://cdn.datatables.net...

    Allan

  • rkbauerrkbauer Posts: 5Questions: 0Answers: 0

    Many thanks! This solved my issue!

Sign In or Register to comment.