Hi,
I would like to save a plotly chart that I have made as a pdf, but I would like to make this happen on a button click in Streamlit. I am able to create the plot ok using streamlit, but am stuck saving out as a pdf
I have added my code below
Blockquote
if st.button(โRun " + str(test) + " Test Toolโ):
# use specs parameter in make_subplots function to create secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# plot a scatter chart by specifying the x and y values
# Use add_trace function to specify secondary_y axes.
fig.add_trace(
go.Line(x=df.index, y=df['Power'], name="KW"),
secondary_y=False)
# Use add_trace function and specify secondary_y axes = True.
fig.add_trace(
go.Line(x=df.index, y=df['Hz'], name="Hz"),
secondary_y=True,)
# Adding title text to the figure
fig.update_layout(
title_text="Hz Vs KW"
)
# Naming x-axis
fig.update_xaxes(title_text="Datetime")
# Naming y-axes
fig.update_yaxes(title_text="<b>KW</b> axis ", secondary_y=False)
fig.update_yaxes(title_text="<b>Hz</b> axis ", secondary_y=True)
#Ensure line is connected
fig.update_traces(connectgaps=True)
st.plotly_chart(fig)
if st.button(โSave Excel Dataโ):
save_path = โโฆ/โฆ/data/output/โ + test + โ/โ + customer
ensure_dir(save_path)
pio.write_image(fig, save_path + datetime.datetime.today().strftime("%d-%m-%Y") + '_' + test + '_' + customer + '.pdf')