Multiline Text in plotly.graph_objects.table

I have been trying to display a multiline text in the cell of a plotly.go.table. I tried incorporating \n and html line break, however none seem to work. Any insights on this?

Hi William,

I believe this is what you are looking for, style_cell = {‘whitespace’:‘pre-line’}. I found it in the link here

 columns=[{"name": i, "id": i, "editable":True} for i in df.columns],
 'whiteSpace': 'pre-line'

Hi @twelsh37, I think you’re referring to Dash’s DataTable. I am using plotly.go.table object

@williamwirono, You are completely correct. I have punched myself in the face. Time to go off and figure this out. Back in a bit with an answer hopefully

Ok SO I had another stab at this. From what I have read you wish to have multi-line content in a cell in a plotly python datatable?

If this is a correct assumption the following provides it

import plotly.graph_objects as go
import plotly.offline as offline

# Sample data - Note the <br> in the second row second cell and third row second cell
# This causes multi line text

data = [
    ['John', 'Doe', 'New York', 'United States'],
    ['Jane', 'Smith<br>Smithson', 'London', 'United Kingdom'],
    ['Michael', 'The<br>Quick<br>Brown<br>Fox<br>Jumped<br>Over<br>The<br>Lazy<br>Dog', 'Paris', 'France'],
    ['Emily', 'Brown', 'Sydney', 'Australia'],
    ['David', 'Lee', 'Tokyo', 'Japan'],
    ['Sarah', 'Wilson', 'Berlin', 'Germany'],
    ['Daniel', 'Taylor', 'Toronto', 'Canada'],
    ['Olivia', 'Anderson', 'Rome', 'Italy'],
    ['Matthew', 'Thomas', 'Madrid', 'Spain'],
    ['Emma', 'Roberts', 'Moscow', 'Russia']

# Create the datatable
datatable = go.Table(
    header=dict(values=['First Name', 'Last Name', 'City', 'Country']),
    # Use cells to define cell attributes
    cells=dict(values=list(zip(*data)), font=dict(size=12)),
    columnwidth=[100, 100, 100, 100],

# Set the layout
layout = go.Layout(
    title='Sample Datatable',

figure = go.Figure(data=[datatable], layout=layout)

# Save to HTML file
offline.plot(figure, filename='datatable.html', auto_open=True)

this outputs as such

I hope this answers your query


Silly me. I had included the slash inside the br tag. Thanks @twelsh37! It worked!

No worries. Im glad I could help. I am always getting tripped up on things like this. I like looking at some forum posts and just learning stuff for the sake of learning it