Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display interactive plotly chart (.html file) on GitHub Pages

I've created the following plotly plot like this:

import plotly
labels = ['Oxygen', 'Hydrogen', 'Carbon_Dioxide', 'Nitrogen']
values = [4500, 2500, 1053, 500]

trace = plotly.graph_objs.Pie(labels=labels, values=values)
plotly.offline.plot([trace], filename='basic-pie-chart')

Then I created the html as such:

print(plotly.offline.plot([trace], include_plotlyjs=False, output_type='div'))

Running the code above generates an .html file that I can view in my browser.

Is there a way to display the .html file in the middle of a markdown file on my GitHub Pages, so I can use the interactive features of plotly?

Here is a similar question that I asked

like image 526
Ethan Avatar asked Mar 03 '20 18:03

Ethan


People also ask

How do I view a Plotly graph in GitHub?

python, html, markdown, plotly You need to enable Github Pages for the repo in the Settings but you don't need to use Jekyll. You can commit the output files of write_html() and push it to the repository. After that you can access the graph by using URL in format <username>. github.io/<repository>/<filepath> .

How do you share an interactive Plotly chart?

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.

How do I show my graph on GitHub?

Accessing the network graph On GitHub.com, navigate to the main page of the repository. Under your repository name, click Insights. In the left sidebar, click Network.

Is Plotly interactive?

Plotly produces interactive graphs, can be embedded on websites, and provides a wide variety of complex plotting options. The graphs and plots are robust and a wide variety of people can use them.


1 Answers

If you use Jekyll in your GitHub pages site.

Prepare your data:

import plotly.graph_objects as go

labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
values = [4500, 2500, 1053, 500]
fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
fig.show()

Generate HTML file:

import plotly.io as pio

pio.write_html(fig, file='figure.html', auto_open=True)

Upload the figure.html file and commit it to _includes folder in the root of your site repository.

Now if you are using markdown to create your posts, you can use include tag and call figure.html in your post with something like this:

{% include figure.html %}

Commit this line to your post .md file in the _posts folder. Check results.

like image 197
Plo_Koon Avatar answered Sep 22 '22 12:09

Plo_Koon