1

I am trying to build a table in plotly with callback, I am using Go.Table but I am unable to create multiple headers

1 Answer 1

3

If I was correct read docs, you can not create multiple headers.

First possible solution is to move headers to values:

import plotly
import plotly.graph_objs as go

trace = go.Table(
    header=dict(values=['Version', 'Baseline', 'Promo', 'VDP+']),
    cells=dict(values=[['', '08/20 to 08/27','08/13 to 08/20', '08/06 to 08/13',\
                        '07/30 to 08/06'],
                       ['Current Month: Aug 18', '', '', '', ''],
                       ['Current Month: Aug 18', '', '', '', ''],
                       ['Current Month: Aug 18', '', '', '', '']]))

data = [trace] 
plotly.offline.plot(data, filename = 'basic_table.html')

Looks like:

First solution

But you can not operate with them such as columns what is not great.

Second possible solution is to specify prefix(or suffix - depends what would you like more):

import plotly
import plotly.graph_objs as go

trace = go.Table(
    header=dict(values=['Version', '.Baseline', '.Promo', '.VDP+'], 
                prefix = ['','Current_Month:_Aug_18', 'Current_Month:_Aug_18',\
                          'Current_Month:_Aug_18'],
                ),
    cells=dict(values=[['08/20 to 08/27', '08/13 to 08/20', '08/06 to 08/13', \
                        '07/30 to 08/06'],
                       ['', '', '', ''],
                       ['', '', '', ''],
                       ['', '', '', '']]))

data = [trace] 
plotly.offline.plot(data, filename = 'basic_table.html')

And in this case, you can add your columns as prefix or suffix.

Looks like: second solution

Update: Yep, you can create an empty row (just do not specify headers): empty row

Update: Currently I found the way to get what you need:

import plotly
import plotly.graph_objs as go

trace = go.Table(
    header=dict(values=[['Version', ''],
                        ['Baseline', 'Current Month: Aug 18'],
                        ['Promo', 'Current Month: Aug 18'],
                        ['VDP+', 'Current Month: Aug 18']]),
    cells=dict(values=[['08/20 to 08/27', '08/13 to 08/20', '08/06 to 08/13', \
                        '07/30 to 08/06'],
                       ['', '', '', ''],
                       ['', '', '', ''],
                       ['', '', '', '']]))

data = [trace] 
plotly.offline.plot(data, filename = 'basic_table.html')

Looks like: This is what you want, is not it?

I can not hide one line but the whole lines of headers(add line = dict(width=0) after headers values): hmm Or set the color of lines but for all the lines again (with same results as above)

Sign up to request clarification or add additional context in comments.

5 Comments

This is helpful, i tried the prefix-suffix way , but the customer is bent on adding headers.
Also, is there a way to hide a header all together , i get a empty row if I dont pass a header trace. ?
@saket-dabi, as I correct understand you, you can get empty rows (see updated answer)
But , as in your case as well, the empty top row (when no header is passed) is still visible. Is there a posibility we can hide it completely ? or remove grid lines from there.
@saket-dabi, I am updated answer. In plotly you cannot remove one particular line as I know

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.