Black Lives Matter. Please consider donating to Black Girls Code today.

Dash - Just display straight HTML?

Hi,
I’m new to Dash so…
Just a quick question. Using dash with plotly in python…

I see there at all these calls to make html tags… html.H1() etc…
But I have a load of html text I need to display.
ITs already in a file and I would prefer just to cut and paste it.
Is there any way just to have Dash dump out a string containing HTML tags?
And not have it write out the tags but actually let them be interpreted as HTML by the browser?

mystring = "<BR/> This is the first sentence. <BR/> this is the second"

gets output as

This is the first sentence.
This is the second.

Rather than as
<BR/> This is the first sentence. <BR/> this is the second

Thanks

See dash_dangerously_set_inner_html

Thanks …
I did a ‘pip install’ of that and tried to use it as per the readme.

html.Div([
                                    dash_dangerously_set_inner_html.DangerouslySetInnerHTML('''
                                    <h1>Header</h1>
                                '''),
                                ])

But now I get a warning in vscode that says

Module 'dash_dangerously_set_inner_html' has no 'DangerouslySetInnerHTML' member

That’s just a warning, you can ignore that. We used to dynamically generate the components on-the-fly and so code editors would complain. We don’t do that with newer components but haven’t ugpraded this library yet.

Thanks @chriddyp, but I wasn’t getting any output … just wasn’t outputting anything at all on the page…
So I just gave up and went with dcc.markdown… and that’s doing the job well enough.

Thanks again for taking the time

Actually… interesting to note…

dcc.Markdown actually has a property called dangerously_allow_html !!

Anyone else who might be interested :slight_smile:

https://dash.plotly.com/dash-core-components/markdown

1 Like