PyLDAvis Component

Hello,

I’m trying to leverage the dash-dangerously-set-inner-html custom component.

I have the following HTML file:

<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/bmabey/pyLDAvis/files/ldavis.v1.0.0.css">
<div id="ldavis_el239681122130198885674280583"></div>
<script type="text/javascript">
...
</script>

It basically renders graphs like the ones in this python notebook: http://nbviewer.jupyter.org/github/bmabey/hacker_news_topic_modelling/blob/master/HN%20Topic%20Model%20Talk.ipynb#topic=0&lambda=1&term= (except my file is available as a standalone .html file)

I tried to include the content of the file in a dash-dangerously-set-inner-html section. It is actually well contained in the page source when I investigate, but I can’t see the graph.

Is there a way I can display this html file in a Dash application?

In advance, thanks.

1 Like

Very much +1! Would like to know this one too, as pyLDAvis and Dash are both amazing would be great to combine them in a Dash app.

You may find the beginning of an answer with the pyldavis_dash custom component I implemented. It’s quick and dirty, but it seems to work fine for my needs.

  • Clone it
  • pip install -e .
  • Argument you pass to data is the var section extracted from the htmlvis generated by pyLDAvis.save_html()
1 Like

Also trying to display a pyLDAvis html file but I can’t quite follow the advice above.

So I have my the output html file, but I don’t quite understand what “just extract the var section” means and what dash component should I be using?

Thanks

1 Like

This link might be helpful for serving static assets such as images and html files:
https://dash.plot.ly/dash-deployment-server/static-assets

I ended using an Iframe to display the html file:

html.Iframe(src=app.get_asset_url(lda_html_file),
                                            style=dict(position="absolute", left="0", top="0", width="100%", height="100%"))
2 Likes

Hey, thank you!!! You have no idea how many hours I have been stuck here. Now I am able to render an html file as a dash component. Thank you!

1 Like