When using either st.write(fig) or st.plotly_chart(fig) to display two tables, I get a huge amount of whitespace between them.
Even if i resize the tables with a smaller height, the white space remains but the table gets shorter.
fig.update_layout(width=width, height=height, title_text=title_text)
Hi @Andrew_Holoska -
Would it be possible to post a screenshot and/or code snippet to display this behavior?
Best,
Randy
fig = create_plotly_table(df_list_clean[0], width=1200, height=600, index_width=1300, title_text=trade_date.strftime('%m-%d-%Y'))
st.plotly_chart(fig, use_container_width=True)
fig = create_plotly_table(df_list_clean[1], width=1200, height=600, index_width=1300, title_text='5 Day Average')
st.plotly_chart(fig, use_container_width=True)
def create_plotly_table(df, width, height, index_width=None, title_text=None):
font_color = [['red' if boolv else 'black' for boolv in df[col].astype(str).str.contains('-')] for col in
df.columns]
rowEvenColor = 'lightgrey'
rowOddColor = 'white'
rows = df.shape[0]
row_colors = [rowOddColor, rowEvenColor] * (rows // 2) + [rowOddColor] * (rows % 2)
col_width_default = 800
if not index_width:
index_width = col_width_default
table_data = [go.Table(
columnwidth=[index_width] + [col_width_default for i in df.columns],
header=dict(values=list(df.columns),
align='right',
font=dict(size=14)),
cells=dict(values=[df[col] for col in df.columns],
align='right',
line_color='darkslategray',
fill_color=[row_colors] * len(df.columns),
font_color=font_color))
]
fig = go.Figure(data=table_data)
fig.update_layout(width=width, height=height, title_text=title_text)
return fig