Hi
I have bunch of plotly graphs in my streamlit application. Is there any way where I can change the name of the plot when I download it?
Thank You
Hi
I have bunch of plotly graphs in my streamlit application. Is there any way where I can change the name of the plot when I download it?
Thank You
Morning and welcome to the community.
Have you not triedthe st.download button?
st.download_button(label='Download', data=image, file_name=new_file_name, mime='image/png')
The below code demonstrates what I mean but will give you a 404 as it canβt locate the image. Iβm on a train, so no more time
import streamlit as st
import plotly.graph_objects as go
# Create a bar chart with 4 bars
fig = go.Figure(data=[
go.Bar(x=['Category 1', 'Category 2', 'Category 3', 'Category 4'], y=[10, 20, 15, 12])
])
# Display the bar chart using st.plotly_chart()
st.plotly_chart(fig)
# Add a download button to rename the downloaded file
if st.button('Download Chart'):
# Convert the figure to an image
image = fig.to_image(format='png')
# Prompt the user to enter a new file name
new_file_name = st.text_input('Enter a new file name', 'chart.png')
# Download the image with the new file name
st.download_button(label='Download', data=image, file_name=new_file_name, mime='image/png')
I tried this but it is showing me Value Error for Kaleido. I installed and imported it yet the error remains