Skip to content

[BUG] Cannot change locale with external CDN source #880

Description

@Batalex

Describe your context

dash==1.1.1
dash-core-components==1.1.1
dash-html-components==1.0.0
dash-renderer==1.0.0
dash-table==4.1.0

Describe the bug

To change Plotly language (modebar + number format), one need to:

  1. load the localization file
  2. Set the locale config key for each graph

Unfortunately, this is problematic with Dash if you want to use the CDN link. From Dash documentation:

External css/js files are loaded before the assets.

which is fine most of the time. However, here is Plotly.js documentation on localization:

After the plotly.js script tag, add [...] the locale definition

Here is the resulting footer of adding the CDN link to external_scripts:

...
<script src="https://cdn.plot.ly/plotly-locale-fr-latest.js"></script>
<script src="/_dash-component-suites/dash_core_components/plotly-1.49.1.min.js?v=1.1.1&m=1565128596"></script>
...

The modebar is not translated in this case.

Expected behavior

Here is the footer when loading the localization file as a local asset:

...
<script src="/_dash-component-suites/dash_core_components/plotly-1.49.1.min.js?v=1.1.1&m=1565128596"></script>
<script src="/_dash-component-suites/dash_core_components/highlight.pack.js?v=1.1.1&m=1565030553"></script>
<script src="/_dash-component-suites/dash_core_components/dash_core_components.min.js?v=1.1.1&m=1565131287"></script>
<script src="/_dash-component-suites/dash_html_components/dash_html_components.min.js?v=1.0.0&m=1561057513"></script>
<script src="/assets/plotly-locale-fr.js?m=1566399183.1702719"></script>
...

The localization file is indeed loaded after Plotly.js, and it works as expected.

Also, this issue happens as well with serve_locally=False .

Suggestion

We can specify some attributes (namely: src, integrity, crossorigin) for each external script, maybe we could add an order indication.
Or perhaps the localization could be a parameter for the Dash application?

Edit: typo

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions