Wordcloud

Hey,
How can I create Wordcloud in Streamlit?

Hi @theamitbhardwaj Welcome to the community,

Creating wordclouds is not something that streamlit supports out of the box but you can create wordclouds convert them to an array and use st.image to show it,

You can use this library for generating word clouds https://github.com/amueller/word_cloud

import streamlit as st
from wordcloud import WordCloud

wc = WordCloud().fit_words({"A": 2, "B": 2, "C": 3})

st.image(wc.to_array())

image
Hope it helps!

4 Likes

Hey, Thanks Yes it’s solved my purpose.

Hi @theamitbhardwaj

I know that it is a late answer, but I share it here anyway for the people who will need this in the future.
I wrote a custom component on Streamlit, which allows you to easily build interactive wordcloud visualizations, like the following:

For using it, you just need to install streamlit-wordcloud
pip install streamlit-wordcloud

Then you can use this code as an example:

import streamlit as st 
import streamlit_wordcloud as wordcloud
words = [
    dict(text="Robinhood", value=16000, color="#b5de2b", country="US", industry="Cryptocurrency"),
    dict(text="Personio", value=8500, color="#b5de2b", country="DE", industry="Human Resources"),
    dict(text="Boohoo", value=6700, color="#b5de2b", country="UK", industry="Beauty"),
    dict(text="Deliveroo", value=13400, color="#b5de2b", country="UK", industry="Delivery"),
    dict(text="SumUp", value=8300, color="#b5de2b", country="UK", industry="Credit Cards"),
    dict(text="CureVac", value=12400, color="#b5de2b", country="DE", industry="BioPharma"),
    dict(text="Deezer", value=10300, color="#b5de2b", country="FR", industry="Music Streaming"),
    dict(text="Eurazeo", value=31, color="#b5de2b", country="FR", industry="Asset Management"),
    dict(text="Drift", value=6000, color="#b5de2b", country="US", industry="Marketing Automation"),
    dict(text="Twitch", value=4500, color="#b5de2b", country="US", industry="Social Media"),
    dict(text="Plaid", value=5600, color="#b5de2b", country="US", industry="FinTech"),
]
return_obj = wordcloud.visualize(words, tooltip_data_fields={
    'text':'Company', 'value':'Mentions', 'country':'Country of Origin', 'industry':'Industry'
}, per_word_coloring=False)

For more options and examples, you can refer to this repo:

Hope this helps!

6 Likes

This is really cool!. I really impressive.
But one question, have you try to link it to cloud database? Such as Firestore?

I have tried few times before , but still cannot solve this problem.