Live table with data in plotly

In addition to graphing, is it possible to create a live updating table with data using Python API? Where can I find the documentation for that?

Any help will be appreciated.

Hi. Did you figure this out?

1 Like

Hi @aelayyan,

This is now possible using the graph_objs.Table (https://plot.ly/python/table/) trace and a FigureWidget (https://plot.ly/python/widget-app/).

For example, display an initial table like this:

import plotly.plotly as py
import plotly.graph_objs as go

trace = go.Table(
    header=dict(values=['A Scores', 'B Scores'],
                line = dict(color='#7D7F80'),
                fill = dict(color='#a1c3d1'),
                align = ['left'] * 5),
    cells=dict(values=[[100, 90, 80, 90],
                       [95, 85, 75, 95]],
               line = dict(color='#7D7F80'),
               fill = dict(color='#EDFAFF'),
               align = ['left'] * 5))

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

newplot-1

Then update the table’s cells, and the table displayed above will update with the new values

table = fig.data[0]
table.cells.values = [[10, 9, 8, 9],
                      [9.5, 8.5, 7.5, 9.5]]

newplot-2

Hope that helps!
-Jon

Thank you Jon. How would you apply this to the live graphing ? I have a table that keeps updating but I want the graph that is drawn on plotly to update regularly with the new data.

Hi @aelayyan,

The go.Table trace in the example above is a trace just like go.Scatter, go.Bar etc. As long as you create and display your graph as a FigureWidget in the notebook you can update it by assigning new values to the properties of the traces in the figure (just like the table.cells.values = ... call above).

If that’s not clear, feel free to post a small example with:

  • a couple of snapshots of the data you want to display (data at time1, time2, etc.)
  • The code for a graph of the data at time1

-Jon

Hi @jmmease! I am wondering how I can update my Table once I have applied the necessary changes. I am trying to avoid using fig.show() since it keeps on creating new copies every time I change a value using my slider. My code is below. Thank you!

def response(change):
    updated_colors = []
    objective_weights = []
    for text in tweet_data_tuple[0]:
        # if greater than the objectiveness threshold then it is subjective b/c closer to 1 is more subjective
        sentiment_tuple = nlp_obj.sentiment(text)
        if (sentiment_tuple[0] < polarity.value) or (sentiment_tuple[1] > objectiveness.value):
            updated_colors.append('red')
        else:
            updated_colors.append('lightcyan')
    table = fig.data[0]
    table.cells.fill = dict(color = [updated_colors, updated_colors])
    fig.show()

As you can see I am just updating all the background colors here:

table.cells.fill = dict(color = [updated_colors, updated_colors])

hi there, hopefully you’re on linux. use a crontab entry to call your script that updates the cells. i am set for doing this. marvelous. best and success!