Read text from file into html.Div()

Hi,

How can I read text from file into html.Div(), but with text format of file (line by line) ?
I want display text/code of this file in app like in code editor.

Thank you

import dash 
import dash_core_components as dcc 
import dash_html_components as html 

# from this file, like this: 

with open('test.py') as this_file:
    for a in this_file.read():
        print(a) 

# to app 

app = dash.Dash(__name__) 

app.layout = html.Div([
                html.Div([
                            # here I want to display text of code line by line (like in text editor)

                ])
])



if __name__=='__main__':
    app.run_server()

This works with a simple ‘test.py’ :

import dash 
import dash_core_components as dcc 
import dash_html_components as html 

# from this file, like this: 
text_markdown = "\t"
with open('test.py') as this_file:
    for a in this_file.read():
        if "\n" in a:
            text_markdown += "\n \t"
        else:
            text_markdown += a

# to app 

app = dash.Dash(__name__) 

app.layout = html.Div([
                html.Div([
                           dcc.Markdown(text_markdown)
                ])
])



if __name__=='__main__':
    app.run_server()
1 Like

Thank you very much for your response.
It works well.

Can I ask you please ? Where did you find these tags documentation of Markdown? because I can’t find tags that work anywhere.
Is it React-Markdown ?

Thank you again

I do not fully understand your question, but here is the documentation about markdowns and here is the documentation about string backslash.

I am sorry, It is not a Markdown, It is a String Literals.

Thank you for your response and links.

:grinning: