I want to plot math symbols in a plotly dash app.
For example, I've Tried this:
import dash
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div(
children=[
html.P(r'$ Area (m^{2}) $'),
dcc.Markdown(r'$ Area (m^{2}) $')
]
)
app.run_server()
and this was the result:
How can I get these result?
MathJax 3 works in Dash v2.3.0 which includes Plotly.js v2.10.0 with Markdown. Example: dcc.Markdown('$$y=x+1$$', mathjax=True)
You can try Mathjax. The following works at my end (Python 3.9.1, dash==1.19.0, dash-html-components==1.1.2)
First create a javascript file (anyname.js) in the assets folder of your current project. In that file have just the following line:
setInterval("MathJax.Hub.Queue(['Typeset',MathJax.Hub])",1000);
Then back to your python file:
from dash import Dash
import dash_html_components as html
MATHJAX_CDN = '''
https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/
MathJax.js?config=TeX-MML-AM_CHTML'''
external_scripts = [
{'type': 'text/javascript',
'id': 'MathJax-script',
'src': MATHJAX_CDN,
},
]
app = Dash(__name__, external_scripts=external_scripts)
app.layout = html.Div(
children=[
html.P('''\(Area\)(\(m^2\)) '''),
]
)
app.run_server()
Some caveats:
If you are able to address any of the two caveats do let me know.
Mathjax version 2.7.9 works for me. (I don't have enough Reputation to comment, else this would be one.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.