jbesomi / texthero

Text preprocessing, representation and visualization from zero to hero.
https://texthero.org
MIT License
2.89k stars 239 forks source link

Any way I can upload texthero visualization plot to my Plotly dashboard? #29

Closed Jacklau9515 closed 4 years ago

Jacklau9515 commented 4 years ago

Hi,

I am just curious about if it is doable I can directly upload the plot to my plotly dashboard once called hero.scatterplot()?

chart_studio.tools.set_credentials_file(username='username', api_key='token') chart_studio.tools.set_config_file(world_readable=True, sharing='public')

Regards, Jack

Jacklau9515 commented 4 years ago

figured it out, thx

jbesomi commented 4 years ago

Hi @Jacklau9515. Thank you for your issues. Would you mind sharing how you solved it?

Maybe other developers will need this information too.

Regards

Jacklau9515 commented 4 years ago

Hi @Jacklau9515. Thank you for your issues. Would you mind sharing how you solved it?

Maybe other developers will need this information too.

Regards

Hi @jbesomi. No worries, and I will share my code below:

import texthero as hero
import pandas as pd

import chart_studio
import chart_studio.plotly as py

chart_studio.tools.set_credentials_file(username='your_username', api_key='your_apikey')
chart_studio.tools.set_config_file(world_readable=True, sharing='public')

df = pd.read_csv(
    "https://github.com/jbesomi/texthero/raw/master/dataset/bbcsport.csv"
)
df['pca'] = (
    df['text']
        .pipe(hero.clean)
        .pipe(hero.tfidf)
        .pipe(hero.pca)
)

fig = hero.scatterplot(df, col='pca', color='topic', title="PCA BBC Sport news", return_figure=True)
py.plot(fig, filename='bbc-test', auto_open=True)

Please feel free put it into your document if you wish :)

jbesomi commented 4 years ago

Thank you @Jacklau9515. Great! If you have any other feedback and/or advice, please let us know. Regards