I am trying to display a wordcloud using the stylecloud module. Everything works well but the ide returns a warning message saying: “Starting a Matplotlib GUI outside of the main thread will likely fail.” Here is the sample code;
import stylecloud
from stop_words import get_stop_words
import streamlit as st
from apps.data import get_data
covid_data = get_data('data/bow.csv')
def app():
st.title("Wordcloud")
stop_words = get_stop_words('english')
concat_quotes = ' '.join(
[i for i in covid_data.text_without_stopwords.astype(str)])
t=stylecloud.gen_stylecloud( # file_path='SJ-Speech.txt',
text=concat_quotes,
icon_name='fas fa-apple-alt',
background_color='black',
output_name='apple.png',
collocations=False,
custom_stopwords=stop_words)
st.write(t)
Cant find a solution on line. How do you go about this?
Hi @Grivine-19, welcome to the Streamlit community!
Based on the following line in the code, it appears that this package only writes to a file:
If that’s truly the case, then the solution would be to use st.image() to read in the picture to the Streamlit app. You might also ask the maintainer of the package to add a Streamlit display method, it likely wouldn’t be a ton of effort for them.
Thank you so much @randyzwitch . This indeed is the solution to the challenge, saving as an image then using st.image function works in this case.
I however got an error when I deployed my app:
ImportError: cannot import name ‘makeMappingArray’ from ‘matplotlib.colors’ (/home/appuser/venv/lib/python3.7/site-packages/matplotlib/colors.py)
According to Matplotlib, the function was deprecated since V3.34. See here. On my local machine, I had to copy-paste the function to the colors.py file for it to run. I got the function from this site.
In my code, I imported *matplotlib.pyplot as plt but never did I call the makeMappingArray function. Why does the streamlit app still need it to run both locally and on the streamlit sharing platform? How can it be corrected?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.