Wordcloud image download issues

Hi community :slight_smile:

I am creating an app that lets users creating a wordcloud image after scraping text from a webpage.

I wanted to add a download feature of the wordcloud created, with st.download and a button, but once clicked nothing happens and page goes back to initial state. Below the code, thanks

Steps to reproduce

Code snippet:

 if st.button("Scrape"):
                text = get_text(URL)
                # create a wordcloud
                wordcloud = WordCloud(width=800, height=400, background_color="white", stopwords=STOPWORDS).generate(text)
                # wordcloud title
                st.markdown('#### Wordcloud of {}'.format(URL))
                plt.figure(figsize=(10, 5))
                plt.imshow(wordcloud, interpolation="bilinear")
                plt.axis("off")
                st.pyplot()
                # create a button to save the wordcloud as an image
                if st.button("Save Wordcloud"):
                    wordcloud.to_file("wordcloud.png")
                    st.success("Wordcloud saved as an image")

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

I would excpect to get the wordcloud image downloaded

Hope anyone can help thanks, Marcello

Hereโ€™s a response to the nested buttons question with links to several threads you can explore.