Dash print dataframe with multiple line in one cell

Hello,

Currently I have a pandas dataframe :

df = pd.DataFrame({
    "date": ["20210613", "20210614", "20210615"],
    "user": ["A\nB", "C", "D"],
    "machine" : [1, 0, 3]
})

image

I wonder if there is any way to print a table like this:

image

no matter using dcc.Textarea or dash_table.DataTable is OK.

Currently I still can not figure out a good way to achieve this, many thanks.

Hi @JimChen

You can do that using markdown. See more info here


import dash
import dash_table
import pandas as pd

df = pd.DataFrame({
    "date": ["20210613", "20210614", "20210615"],
    "user": ["A \\\n B", "C", "D"],
    "machine" : [1, 0, 3]
})

app = dash.Dash(__name__)

app.layout = dash_table.DataTable(
    id='table',
    columns=[{"name": i, "id": i, "presentation": "markdown"} for i in df.columns],
    data=df.to_dict('records'),
)

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


image

1 Like