🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

How do I display a text file directly on the User Interface

I have a text file which consists of say 100 lines of text. Now, I want to display the contents of text file in the User Interface as a scrollable view.
I tried reading the whole text file to a string variable and then returning the string variable as output. But that escapes all the new line characters and the whole text file gets displayed continuously without line breaks.

I also tried Dash data tables to store the string inside one cell of a dataframe. But that also doesn’t give the required output. I mean the formatting gets all nasty.

Can someone please guide me in displaying a text file on the User Interface having the same formatting(retaining the line breaks)

1 Like

try html.Div(your_string, style={'whiteSpace': 'pre-line'}). See more options here: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

1 Like