3

I am using plotly.go to make a table and export to html, however the columns on the table are not static, they can be dragged and rearranged with the mouse. I'm trying to find a simple way to make the table static while still exporting to html.

import pandas as pd
import plotly.graph_objects as go

df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
                   columns=['a', 'b', 'c'])

fig = go.Figure(data=[go.Table(
    header=dict(
        values=list(df),
        line_color='darkslategray',
        fill_color = 'lightskyblue',
        align='center'),
    cells=dict(
        values=[df.a, df.b, df.c],
        line_color='darkslategray',
        fill_color='lightcyan',
        align='center'))

])
fig.show()
fig.to_html('table.html')

I've tried using staticPlot: true, but it doesn't seem like that's an attribute in graph_objects.

J-Help
  • 61
  • 5
  • 1
    Does this helps? https://stackoverflow.com/questions/59815797/plotly-how-to-save-plotly-express-plot-into-a-html-or-static-image-file – Punker Jan 21 '21 at 20:43
  • Thanks for the suggestion @GlebV, unfortunately this does not help. My goal is to make the table static, instead of exporting to a png or other file type. – J-Help Jan 21 '21 at 22:07
  • If you prefer a specification where columns cannot be dragged, why not use FigureFactoryTable? [See this](https://plotly.com/python/figure-factory-table/). – r-beginners Jan 22 '21 at 02:41
  • Maybe the [dash table](https://dash.plotly.com/datatable) can be used instead. The columns itself are static but its not directly available as html as far as I can tell. – ConstantinB Jan 22 '21 at 13:52

1 Answers1

1

I was able to get a static table by adding the following to the code:

fig.show()
fig.to_html('table.html', config={'staticPlot': True})

The one thing to keep in mind is that the mouse icon still changes to look like columns can be dragged, but the columns are static.

J-Help
  • 61
  • 5