I have created two Plotly tables that are of different dimensions and want to place them beside each other. Is there a way to perform this task without the implementation of dash?
Asked
Active
Viewed 983 times
1 Answers
2
Yes, you can make the tables subplots of type table:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig = make_subplots(rows=1, cols=2, specs=[[{"type": "table"}, {"type": "table"}]])
fig.add_trace(
go.Table(
header=dict(values=["A", "B"]),
cells=dict(values=[[1, 2, 3, 4], [2, 4, 6, 8]]),
),
row=1,
col=1,
)
fig.add_trace(
go.Table(
header=dict(values=["C", "D", "E"]),
cells=dict(values=[[3, 6, 9, 12, 15], [4, 8, 12, 16, 20], [5, 10, 15, 20, 25]]),
),
row=1,
col=2,
)
fig.show()

5eb
- 14,798
- 5
- 21
- 65
-
Thanks! Is there a way to incorporate the data type ( for instance percentage, float with 2 integers etc.) with the individual tables (In my case the tables do not have the same data format) ? – Mat Aug 27 '21 at 07:27
-
1Each table works separately and can have its own formatting. This is out of the scope of this question, but you can add a `format` property to the `cells` dictionaries. For example: `cells=dict(values=[[1, 2, 3, 4], [2, 4, 6, 8]], format = [None, ",.2f"],)` formats the second column to have two decimal places. Adjust according to your needs. If an answer solves your question problem be sure to upvote and accept. – 5eb Aug 27 '21 at 07:39
-
Thanks a lot! Works perfectly....Just one query, is there a way to reduce the gap between the two tables? – Mat Aug 28 '21 at 04:19
-
I haven't tested it out, but [this](https://stackoverflow.com/a/31528495/9098350) probably works. – 5eb Aug 28 '21 at 05:03