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

Table View -- Table not showing in plot() (but showing fine in jupyter using iplot() )

Can’t get a simple example table to show as separate offline plot. Get a javascript error:

image

import pandas as pd
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=False)

trace = go.Table(
header=dict(values=[‘A Scores’, ‘B Scores’]),
cells=dict(values=[[100, 90, 76,76],
[80, 90,45,48],
]))

layout = dict(width=500, height=300)
data = [trace]
fig = dict(data=data, layout=layout)

iplot(fig, filename = ‘basic_table.html’) #shows ok in jupyter notebook

plot(fig, filename = ‘basic_table.html’) #doesn’t show in separate browser windows with javascript error

this is what it look like in the notebook:

image

Ok I have work around for this now.

  1. in the header the values are apparently expected to be list of lists. This is probably for multi-rows.
  2. width property must be defined on the level of cells { line }, otherwise the cells wont render because of an error looking for “width” property

trace = go.Table(
columnwidth = [250,250],
header=dict(values=[ [‘A Scores’], [‘B Scores’]],
height = 50,
line = dict(color=‘rgb(50,50,50)’, width= 1),
align = [‘left’]*5,
font = dict(color=[‘rgb(45,45,45)’]*5, size=14),
fill = dict( color = ‘#d562be’ )
),

cells=dict(values=[[100, 90, 76,76],
                   [80, 90,45,48],],
           height = 45,
              line = dict(color='rgb(50,50,50)', width= 1), 
          )
)

layout = dict(width=500, height=500)
data = [trace]
fig = dict(data=data, layout=layout)

iplot(fig, filename = ‘basic_table.html’)
plot(fig, filename = ‘basic_table.html’)