dccMarkdown
is a component for rendering Markdown text, allowing for easy formatting and styling of text content in your Dash app.
Find a few usage examples below.
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
from dash import Dash, dcc
app = Dash()
app.layout = dcc.Markdown('''
# This is an <h1> tag
## This is an <h2> tag
###### This is an <h6> tag
''')
if __name__ == '__main__':
app.run(debug=True)
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
from dash import Dash, dcc
app = Dash()
app.layout = dcc.Markdown('''
*This text will be italic*
_This will also be italic_
**This text will be bold**
__This will also be bold__
_You **can** combine them_
''')
if __name__ == '__main__':
app.run(debug=True)
This text will be italic
This will also be italic
This text will be bold
This will also be bold
You can combine them
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
from dash import Dash, dcc
app = Dash()
app.layout = dcc.Markdown('''
* Item 1
* Item 2
* Item 2a
* Item 2b
''')
if __name__ == '__main__':
app.run(debug=True)
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
from dash import Dash, dcc
app = Dash()
app.layout = dcc.Markdown('''
>
> Block quotes are used to highlight text.
>
''')
if __name__ == '__main__':
app.run(debug=True)
Block quotes are used to highlight text.
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
from dash import Dash, dcc
app = Dash()
app.layout = dcc.Markdown('''
[Dash User Guide](/)
''')
if __name__ == '__main__':
app.run(debug=True)
link_target
is available in Dash 2.4 and later.
Using link_target
you can set the HTML target
attribute for links in your Markdown component.
In this example, we set link_target="_blank"
. When selected, the Dash User Guide link now opens in a new tab or window.
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
from dash import Dash, dcc
app = Dash()
app.layout = dcc.Markdown('''
[Dash User Guide](/)
''',
link_target="_blank",
)
if __name__ == "__main__":
app.run(debug=True)
Text surrounded by single backticks (`) renders as inline code.
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
from dash import Dash, dcc
app = Dash()
app.layout = dcc.Markdown('''
Inline code snippet: `my_bool = True`
Block code snippet:
```python
def sum(a, b):
return a+b
sum(2,2)
```''')
if __name__ == '__main__':
app.run(debug=True)
Inline code snippet: my_bool = True
Block code snippet:
def sum(a, b):
return a+b
sum(2,2)
Only certain languages are supported by default in dccMarkdown
. For more details about how to customize the
languages and color schemes, refer to Syntax Highlighting With Markdown
in Adding CSS & JS and Overriding the Page-Load Template.
dccMarkdown
supports rendering LaTeX. It uses MathJax version 3.2 and can be enabled by setting mathjax=True
on the component. For inline math content, use $
delimiters. For math content that you want to display as a block (usually multi-line content), use $$
. If you need a literal $
, use the HTML entity $
This example has not been ported to R yet - showing the Python version instead.
Visit the old docs site for R at: https://community.plotly.com/c/dash/r/21
from dash import Dash, dcc, html
import plotly.express as px
fig = px.line(x=[1, 2, 3, 4], y=[1, 4, 9, 16], title=r'$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$')
fig.update_layout(
xaxis_title=r'$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$',
yaxis_title=r'$d, r \text{ (solar radius)}$')
app = Dash()
app.layout = html.Div([dcc.Markdown('''
## Introducing LaTeX using MathJax:
This example uses the block delimiter:
$$
\\frac{1}{(\\sqrt{\\phi \\sqrt{5}}-\\phi) e^{\\frac25 \\pi}} =
1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}}
{1+\\frac{e^{-8\\pi}} {1+\\ldots} } } }
$$
This example uses the inline delimiter:
$E^2=m^2c^4+p^2c^2$
### LaTeX in a Graph component:
''', mathjax=True),
dcc.Graph(mathjax=True, figure=fig)
])
if __name__ == '__main__':
app.run(debug=True)
This example uses the block delimiter:
$$
\frac{1}{(\sqrt{\phi \sqrt{5}}-\phi) e^{\frac25 \pi}} =
1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
{1+\frac{e^{-8\pi}} {1+\ldots} } } }
$$
This example uses the inline delimiter:
$E^2=m^2c^4+p^2c^2$
For an introduction to LaTeX math, see LaTeX/Mathematics.
Our recommended IDE for writing Dash apps is Dash Enterprise’s
Data Science Workspaces,
which has typeahead support for Dash Component Properties.
Find out if your company is using
Dash Enterprise.
children
(character | unnamed list of characters; optional):
A markdown string (or array of strings) that adheres to the CommonMark
spec.
id
(character; optional):
The ID of this component, used to identify dash components in
callbacks. The ID needs to be unique across all of the components in
an app.
className
(character; optional):
Class name of the container element.
mathjax
(logical; default FALSE
):
If TRUE, loads mathjax v3 (tex-svg) into the page and use it in the
markdown.
dangerously_allow_html
(logical; default FALSE
):
A boolean to control raw HTML escaping. Setting HTML from code is
risky because it’s easy to inadvertently expose your users to a
cross-site scripting (XSS)
(https://en.wikipedia.org/wiki/Cross-site_scripting) attack.
link_target
(character; optional):
A string for the target attribute to use on links (such as “_blank”).
dedent
(logical; default TRUE
):
Remove matching leading whitespace from all lines. Lines that are
empty, or contain only whitespace, are ignored. Both spaces and tab
characters are removed, but only if they match; we will not convert
tabs to spaces or vice versa.
highlight_config
(named list; optional):
Config options for syntax highlighting.
highlight_config
is a named list with keys:
theme
(a value equal to: ‘dark’ or ‘light’; optional):loading_state
(named list; optional):
Object that holds the loading state object coming from dash-renderer.
loading_state
is a named list with keys:
component_name
(character; optional):
Holds the name of the component that is loading.
is_loading
(logical; optional):
Determines if the component is loading or not.
prop_name
(character; optional):
Holds which property is loading.
style
(named list; optional):
User-defined inline styles for the rendered Markdown.