-
-
Notifications
You must be signed in to change notification settings - Fork 145
Added MathJax CDN to enable Latex #194
base: dev
Are you sure you want to change the base?
Conversation
Thanks @kaushiksk ! We'll need a couple of extra things to get this across the finish line 🏁
Let me know if you need help with this or if you don't have the time to do those steps. And thanks again for your contribution to Dash! 🙌 |
- Added local copy of MathJax for users that are using `serve_locally=True` - Added screenshot test - Bumped version to `0.22.2`
@chriddyp I've made the changes you mentioned. Added an equation in LateX in the title of the Graph. Please do let me know if I've missed out on something. |
Thank you @kaushiksk ! Looking at the screenshot test, it looks like the LaTeX isn't getting rendered :( Now, this could be an issue with percy.io not rendering the MathJax correctly or perhaps we aren't waiting long enough for the MathJax to render. Could you share a screenshot of this test running locally and confirm that it is rendering appropriately? |
@@ -22,6 +22,11 @@ | |||
_this_module = _sys.modules[__name__] | |||
|
|||
_js_dist = [ | |||
{ | |||
'external_url': 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML', | |||
'relative_package_path': 'mathjax-2.7.4.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be mathjax-2.7.4.min.js
- it should match https://github.com/plotly/dash-core-components/pull/194/files#diff-97c91a104c431d0c365565d3ac03ac13R12
We should also rename the file dash_core_components/mathjax-2.7.4.js
to dash_core_components/mathjax-2.7.4.min.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or vice-versa, everything could be labeled mathjax-2.7.4.js
rather than mathjax-2.7.4.min.js
. I don't really have a preference, but they do need to all have the same name 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh my bad. I'll change it in MANIFEST.in
test/test_integration.py
Outdated
self.startServer(app=app) | ||
|
||
graph = self.wait_for_element_by_css_selector('#graph') | ||
time.sleep(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case this was a timing issue, let's try bumping this up to 4
test/test_integration.py
Outdated
]) | ||
self.startServer(app=app) | ||
|
||
graph = self.wait_for_element_by_css_selector('#graph') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an idea - let's "wait for" the actual graph to be rendered rather than just the container. Let's update this CSS selector to be: '#graph .svg-container'
test/test_integration.py
Outdated
'y': [1, 3, 5, 9, 13] | ||
}], | ||
'layout': { | ||
'title': 'Graph of \(y = \frac{x^2 - 2}{4}\)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, this isn't actually valid in plotly.js. Text needs to be all latex or none latex.
Let's use this example from the docs: https://plot.ly/python/LaTeX/
'title': '$\\sqrt{(n_\\text{c}(t|{T_\\text{early}}))}$'
- Updated the test to have only latex in title - Made mathjax filename consisten everywhere
@chriddyp I changed the latex text in the title and fixed the filename issue and bumped the wait time as well. I tested it locally. This is what happens:
As it turns out I get a blank legend and title in the graph given in the docs(https://plot.ly/python/LaTeX/) as well. I'm not sure if it's an issue with my browser. Anyway, I've pushed the necessary changes, let me know what the new screenshots look like. |
The previous commit message should have been "Fixed missing |
@chriddyp Here's how the LateX example from the docs looks like in my Firefox 59.0.2 on Ubuntu 16.04.
I ran the following snippet locally and noticed similar behavior. import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div([
html.Label('Graph'),
dcc.Graph(
id='graph',
figure={
'data': [{
'x': [1, 2, 3, 4, 5],
'y': [1, 3, 5, 9, 13]
}],
'layout': {
'title': '$\\sqrt{(n_\\text{c}(t|{T_\\text{early}}))}$'
}
}
),
])
if __name__ == "__main__":
app.run_server(debug=True) Here's the ouput for the above code: Now if I change the I could see a script tag in the html pointing to the MathJax CDN, so MathJax is getting loaded. |
I think this is just a firefox issue |
test/test_integration.py
Outdated
'y': [1, 3, 5, 9, 13] | ||
}], | ||
'layout': { | ||
'title': 'sqrt{(n_\\text{c}(t|{T_\\text{early}}))}$' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're missing a leading $
here, I believe it should be
$sqrt{(n_\\text{c}(t|{T_\\text{early}}))}$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must've missed that while testing with different inputs. Fixed this. Check perci.io output now, hopefully, this should work.
Is this intended just for graph labels, or would equations render inside a dcc.Markdown component too? |
As far as I know, just graph labels. I'm haven't looked into what it would take for MathJAX to just automatically work everywhere. If anyone knows or would like to do that research, please update the thread :) |
As I understand it, MathJax by default will render any equation strings it finds anywhere in the page--but I wouldn't be surprised if this has been disabled somehow just to be polite? I'm really not sure. There are React components out there which will do MathJax rendering for you, but it seems a shame to write another Dash component using these and possibly be loading the MathJax library twice, if MathJax is already a dependency for the core components. |
Yeah, I think that one issue is that Dash renders everything dynamically, so I'm assuming that we'd to inform MathJax whenever new changes were made. |
It might be nice if there was some kind of "
|
@chriddyp I've shared screenshots from my environment in the comments above. |
It looks like the screenshots that you shared in #194 (comment) were just in Firefox, and that MathJax has issues rendering in Firefox. Could you share screenshots from another browser that doesn't have those issues, like Chrome? |
This PR looks to have gone stale, but in case someone wants to pick it back up: If we only want to support MathJax within plotly.js, the config should be changed to Should we make a |
Solves plotly/dash#242