Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export a plotly dashboard app into a html standalone file to share with the others?

I have built a plotly interactive dashboard, and am looking a way to export this app to HTML format, and share it with others.

Is there any hints for me?

I have googled, and most answer divert me to the following links.

https://plot.ly/python/getting-started-with-chart-studio/

and i have tried to put :

import plotly.io as pio

pio.write_html(app, file='hello_world.html', auto_open=True)

in my app.py after :

if __name__ == "__main__":
    app.run_server(debug=True, port=8052)

but it doesn't work.

like image 426
yts61 Avatar asked Feb 06 '20 14:02

yts61


People also ask

How do you share Dash with someone?

In the dashboard manager, find the dashboard or the group of dashboards you want to share. Click the icon next to the dashboard or group name and choose the option Copy URL link. The dashboard or group URL link will be copied to your clipboard. You can then paste it and send it to the people you want to.

How do you embed Plotly in HTML?

To share a plot from the Chart Studio Workspace, click 'Share' button on the left-hand side after saving the plot. The Share modal will pop-up and display a link under the 'Embed' tab. You can then copy and paste this link to your website. You have the option of embedding your plot as an HTML snippet or iframe.


2 Answers

Assuming your app has many interrelated components, I would suggest you deploy your plotly dash app to heroku: https://dash.plot.ly/deployment

If you have several graph objects, you could export them individually to html with the following code:

plotly.offline.plot(
  # Your plotly go figure here
  show_link=False,
  filename = 'my_file.html'
)

Alternatively, if you want to embed your chart:

from plotly.offline.offline import _plot_html
#Only for embedding
embedable_chart = plotly.offline.plot(fig, include_plotlyjs=False, output_type='div')
f = open("embedable_chart.text", "w")
f.write(embedable_chart)
f.close()
like image 119
Yaakov Bressler Avatar answered Sep 20 '22 23:09

Yaakov Bressler


So I think the answer you needed was "it cannot be done".

To clarify the repeated ask of converting a dashboard to HTML:

HTML is a markup language; it displays text in aesthetic ways, you can use CSS to improve the aesthetics.

The idea of interactivity like a dashboard where onClick() leads to changes in visuals because the csv file was re-queried or filtered or re-calculated is what a server-side brings to the HTML/CSS/JavaScript front-end.

You cannot have a fully encapsulated dashboard with interactivity in an HTML file alone. You must bring server-side logic to the table. This is why everyone is mentioning Heroku, AWS, etc.

Now if your dashboard is not interactive, and it's actually just a bunch of static visuals with some basic hover-over effects; then a standalone HTML file can read in SVGs that contain hover over text prepared. This is what plotly's write_html does (my understanding is plotly.offline.plot just uses this under the hood or something similar).

The gist that someone else noted, duplicated here:

https://gist.github.com/ybressler/e0d40e63a5f35cf2dda65378333c6436

Shows the limits of HTML only "dashboarding". You can show/hide and hover over points, but you can't incorporate sliders that change values without the server side or very bloated and complex show/hide logic hidden somewhere.

Image of 3-D HTML plot with limited interactivity.

like image 28
Carlos Mercado Avatar answered Sep 17 '22 23:09

Carlos Mercado