-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[BUG] Cannot change locale with external CDN source #880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
TLDR: @chriddyp @Marc-Andre-Rivet do you see any problem moving @Batalex interesting - that is certainly a problem, thanks for the report! At some point we may want to handle localization dash-wide, so it can be applied consistently and easily to all elements that show text (see eg plotly/dash-table#300) but we are a ways away from that. There's relatively complicated ordering built into dash right now, primarily via: Lines 600 to 613 in f0b6be9
Which has the effect of ordering things:
Now, seems like it would be more self-consistent to put There's always the option to override the default html template, via |
Hum I believe Mathjax.js has to be loaded before Plotly.js so moving all external scripts after the assets is not a viable alternative |
Ah, you're right - so MathJax must have the opposite bug right now, that it'll work via CDN but not assets. It occurs to me it might not be hard to remove that restriction for MathJax - have plotly.js configure it on the first plot call rather than on script load. And in principle we could do something similar to make locales function either before or after plotly.js, though that may be a little tricky to get right in all cases. But in the spirit of "once is never, twice is always" perhaps this tells us we'll see this problem again and we do need an order param to save everyone from custom index templates. There might be things that need to come even before React, like browser polyfills? So perhaps something like:
|
This can work. Would prefer a named convention. If additional buckets get added or if new features in Dash impact ordering, it becomes easier to have a predictable behavior between releases and to abstract away the ordering. I'd see something like e.g. initial buckets could be
Agreed. I'd be interested in seeing this solution apply to components too through some mechanism. For example, DDK requires the dash-table to be loaded before but there is no way of guaranteeing that atm and a jerry rigged solution was required. Being able to declare that it depends on the dash-table and having the server order the components accordingly would be better. |
It seems like since 1.5.0 and its async dependencies it is now impossible to change the locale due to plotly/plotly.js#4146
|
ah good point. You can put a version of plotly.js in your assets dir, then it'll at least load synchronously - but I don't think it'd be guaranteed to load before the locales even so. plotly/plotly.js#4146 is really the solution we want. |
Order-independent loading of locales will be provided by plotly/plotly.js#4453 As for MathJax, as per plotly/plotly.js#4146 (comment), when
With this change, MathJax should work the same regardless of when it is loaded. |
FYI, PR plotly/plotly.js#4453 is now merged and the associated issue plotly/plotly.js#4146 is closed. |
@antoinerg Let us know when this is released in Plotly.js and we'll update Dash and see about adding a test for this scenario. |
@Marc-Andre-Rivet plotly.js 1.52.0 just landed: https://github.com/plotly/plotly.js/releases/tag/v1.52.0 and it contains the fix (plotly/plotly.js#4453)! |
@Batalex The new |
@Marc-Andre-Rivet Still not resolved on my side... I will share a small reproductible app in order to confirm the behavior. |
Ok, given this very simple app:
The modebar is translated as expected in |
Bump jinja2 from 2.10 to 2.11.3
Bump jinja2 from 2.10 to 2.11.3
Describe your context
Describe the bug
To change Plotly language (modebar + number format), one need to:
locale
config key for each graphUnfortunately, this is problematic with Dash if you want to use the CDN link. From Dash documentation:
which is fine most of the time. However, here is Plotly.js documentation on localization:
Here is the resulting footer of adding the CDN link to
external_scripts
:The modebar is not translated in this case.
Expected behavior
Here is the footer when loading the localization file as a local asset:
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
The text was updated successfully, but these errors were encountered: