How to change the language / locale in Dash (Plotly) or the label of the Plotly toolbar?

Question:

Plotly Toolbar

I have been able to successfully modify Plotly’s toolbar in Dash using a dict (config) passed to dash_core_components.Graph

Now I want to change the “tooltip” or label of the remaining buttons to another language.
The documentation states that I can change de locale (language) of the labels using the “locale” parameter. I’ve seen this both in JavaScript and R docs, being applied to Plotly Graphs or to dash_core_components.Graph:

https://plot.ly/r/locales/

Now I need to do this in Python, but I haven’t been able to do this. This is what I’ve tried:

config_plots = {'modeBarButtonsToRemove':["sendDataToCloud","lasso2d","pan2d","autoScale2d","select2d","zoom2d","zoomIn2d", "zoomOut2d"],
            "locale":"de"}

dcc.Graph(id="plot",config=config_plots,
              figure={"data":plotdata,"layout":layout})

I have added the locale parameter as well to plotly graphs (plotly.graph_objs) and tried with different locales I know that exist, but I’ve had no luck so far.

The question:
How can I customize the text of the labels? Am I missing something using the locale parameter? Is there any way to change the text of the labels so I can translate it without using the locale parameter?

Please note that I know very little of JavaScript so I would prefer to do this in Python if possible

Asked By: David Olmo Pérez

||

Answers:

According to this plotly documentation you need to register any new language first.

In your case this means you need to add

https://cdn.plot.ly/plotly-locale-de-latest.js

to your dashboard.

Either by

app.scripts.append_script({"external_url": "https://cdn.plot.ly/plotly-locale-de-latest.js"})

or by downloading the js file and coping it to the assets folder in your dashboards root folder.

See https://dash.plot.ly/external-resources for more information.

Answered By: phifre

In django-dash-plotly I had to do this:

  • Add the localization script to the external scripts:
        app = DjangoDash(
            self.name,
            external_scripts=[
                "/static/plotly/plotly-locale-es.js",
            ],
        )
  • Configure the Graph with the locale.
    app.layout = [
       dcc.Graph(
            id="my_graph",
            config={"locale": 'es'},
       )
    ]
Answered By: dmcontador