Is it possible to upload Bokeh plots to wordpress.com site? - python

I want to start doing data visualisation with Bokeh and upload it to my wordpress, and so I generated some html like so
from bokeh.plotting import figure,output_file,save
from bokeh.embed import file_html
output_file("line.html")
p=figure(plot_width=400,plot_height=400)
p.circle([1,2,3,4,5],[6,7,2,5,4],size=20,color='navy',alpha=0.5)
save(p)
I then attempted to embed the plot by pasting the saved html into wordpress.com's "HTML" tab when making a new post, and it simply erases it.
This same method works perfectly on blogger.
Is there any way to get past this for wordpress?
Thanks!

You might try the EmbedIt plugin: http://www.matteoionescu.com/wordpress/embed-html/. Just copy the entirety of your Bokeh-generated html file to a "snippet", and embed the snippet in your wordpress post.
I got it to work on my service-hosted wordpress site (not wordpress.com). The plot and tools work fine, but the left edge of the plot always appears in the center of the page (so the plot itself is not centered).
Worth a shot, but as Big red said, javascript might not be allowed at all.

Related

How do I post Python generated GFS plots on my website?

I have a Python script that ingests GFS model data and plots it using matplotlib. How do I get those exact plots to display on a website? I am currently using PythonAnywhere to build my webpage.
It looks like Python Anywhere has a variety of options for how you can host your website/web application--so the details of how to do this will depend on how you are hosting your site.
One option is Flask, and I'll just point you to Matplotlib's example on embedding Matplotlib within Flask.
Another option is to generate the plots statically somewhere, and then upload them into your static website content. I'm not sure how exactly one one would go about that with Python Anywhere.

What does include_plotlyjs="cdn" in plotly python do to the generated HTML?

My goal is to generate an interactive html file from plotly fig and embed this html in my website. I was previously using fig.write_html('name.html'), but in the generated HTML, there are some unwanted symbols like ampersands &&.
Now, I tried adding cdn like fig.write_html('name.html', include_plotlyjs="cdn"), which solves the && problem but I have some questions about this:
On using cdn, is my data still secured/private, and can there be some possible complications on embedding this html to my website?
Is there any better/alternate way of removing the && symbols/cleaning the initial html file generated by plotly?
TIA
The include_plotlyjs="cdn" parameter causes a script tag to be included in the HTML output that references the Plotly CDN ("content delivery network"). This offloads the work of providing the necessary javascript from your server to a more scalable one. A browser will typically cache this making subsequent page loads faster.
Your data security/privacy is not affected by this option.
If the unwanted text you refer to is part of the Plotly JavaScript, it must be loaded however this solution will keep it from appearing in your HTML.
See the documentation for to_html for more information.

How to load and plot csv file using altair package in python?

I have a csv file which has 200000 lines and I would like to plot the data files using altair packagae. Documentation states that for large files, data needs to be passed as URL. This is what I have till now.
import altair
alt.data_transformers.enable('csv')
url = 'path/to/data'
chart = alt.chart(url).mark_line.encode(x= 'time:T', y = 'current:Q')
chart.save('name.html')
But this does not seem to work. Am I missing something obvious here?
When you pass a dataset by URL and save the chart to HTML, the important thing is that the URL is valid for the web browser you use to view the HTML file.
So if you are viewing the chart locally and want to load a local file, use an appropriate file:// URL. If you plan to view the file within a web server that supports relative URLs for loading resources, pass the relative URL between the location of the HTML file and the location of the data file.
But, as a side-note, you mention your data has 200,000 rows: no matter how you pass the data to the Vega-Lite renderer, it's unlikely to perform well with that much data. My personal rule-of-thumb is to avoid Altair/Vega-Lite for datasets with more than ~10,000 rows or so.
Apart from what #jakevdp said, one more thing that I noticed was that in defining your plot, you missed out on the brackets "()" after mark_line in your code.
I tried implementing the code on a smaller dataset with this modification, and it worked great.

Google Time Based Graphs can't be seen as images

I have a chart that is a time based chart. However when I try to publish it as a image - it doesn't seem to physically publish. I get link and when I inspect link I can see the image, but the image is just a blank when you look at the site. I thought this was a browser specific issue - but alas, tried it on linux/microsoft O/S and different browsers - same result - the image is blank.
The interactive version of the graph seems to be working from the get go, in all o/s and browsers.
Is there way to bypass this and have a time-based chart display as an image?
Addendum:
The type of graph is as follows:
The x axis is time and y axis is any relevant value. The graph events that has happened at a given time instant. However with most if not all Google charts, when you click the publish button you have the option to publish the graph as an image or an interactive graph:
However with time-based graphs you still get this option but when you choose to publish it as an image, and go to the published website - there is nothing to be seen there - it's just blank. I have tried different o/s and browsers but no success.
Is there a way to publish the time-based graph as an image that can actually be seen?
This should not have a google-visualization tag. It looks like you are have created a chart in Google docs and are trying to use their 'publish to the web' feature. That is separate from the Google visualization API.

Inputing an MPLD3 graph into Wordpress

I'm having trouble getting my mpld3 plot to show up in my Wordpress page. I make my plot, then use mpld3.save_html() to get an html file that contains my figure. However, when I paste this code into my Wordpress page (using the Text editor, not the visual editor) nothing happens. I paste both the script and div tags. I know my javascript is working because I can write alert('Hello'); inside script tags, which works fine. I've also tried installing the "Insert Javascript & CSS" plugin, which also did not work.
Is there some way to embed these graphs into Wordpress, and if not, how does one embed interactive charts in a Wordpress post?
I suspect that the d3.js and mpld3.js were not found, which would explain why you don't see the chart.
There is a d3_url and mpld3_url that you may want to provide and set to the url of a CDN where the files are available for example See https://mpld3.github.io/modules/API.html#mpld3.fig_to_html
Even after setting that properly you may have problems as this is not the recommended way to use javascript within wordpress. You can also try an embed with stricter separation from wordpress: see http://www.datamaplab.com/posts/embedding-javascript-visualization-wordpress/ for reference.

Categories